Squirrel bug: return statement

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Squirrel bug: return statement

Post by Michiel »

I ran into a bug recently: return statements where the return value is not on the same line as the statement, return null:

Code: Select all

class Test extends AIController {
	
	function Start() {
		AILog.Info("f1: " + f1());
		AILog.Info("f2: " + f2());
		AILog.Info("f3: " + f3());
	}
	
	function f1() {
		return "Hello, world!";
	}
	
	function f2() {
		return
			"Hello, world!";
	}
	
	function f3() {
		return "Hello, " +
			"world!";
	}
	
}
This prints:

Code: Select all

f1: Hello, world!
f2: (null : 0x00000000)
f3: Hello, world!

This is on the latest revision of the NoAI branch.
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Re: Squirrel bug: return statement

Post by glx »

It's not a bug. In squirrel a statements ends with a semicolon or a newline. So you usually can't use multiline statements (f3() is an exception there because '+' requires something)

See http://squirrel-lang.org/doc/squirrel2.html#d0e656
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Squirrel bug: return statement

Post by Michiel »

Aha! That's what you get when you pick up the language from examples. I saw semicolons everywhere so it never registered they're optional. Thanks :)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Squirrel bug: return statement

Post by TrueBrain »

Michiel wrote:Aha! That's what you get when you pick up the language from examples. I saw semicolons everywhere so it never registered they're optional. Thanks :)
It was surprising to everyone :) And it is _very_ annoying ;) (lets face it, which sane language allows both \n and ';' to terminate commands .. it should be either one :)).
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Squirrel bug: return statement

Post by Michiel »

Couldn't agree more :P
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Squirrel bug: return statement

Post by Roujin »

So.. someone would need to nail together some new language that we can use instead of squirrel... but that would be like a bolt out of the blue, wouldn't it? :twisted:
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: Squirrel bug: return statement

Post by Finaldeath »

Dear me, here comes the puns!

Funny, I never realised that, and I thought I had read all the squirrel docs.

Interesting to know, and insane, I agree!
Finaldeath
razielanarki
Engineer
Engineer
Posts: 20
Joined: 08 May 2002 05:01

Re: Squirrel bug: return statement

Post by razielanarki »

TrueLight wrote:which sane language allows both \n and ';' to terminate commands
javascript

but then again... "javascipt" and "sane"... :|
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 14 guests