Array bug in 1.3.7?

Having trouble with the game? Report issues and get help here. Read this first!

Moderator: Forum Moderators

Forum rules
Before reporting issues in this section, you must read the following topic:
Post Reply
genosuke
Posts: 57
Joined: June 23rd, 2005, 7:02 pm

Array bug in 1.3.7?

Post by genosuke »

If an array has no elements and its length is used in a comparison, then the length changes to 1 making the comparison evaluate to true. For example,

Code: Select all

[event]
	name=moveto
	first_time_only=no
	...

	[store_unit]
		variable=horse_store
		[filter]
			type=Horse
			side=3
			[filter_location]
				x=$x1
				y=$y1
				radius=1
				[not]
					terrain=Hh
				[/not]
			[/filter_location]
		[/filter]
	[/store_unit]

	#DEBUG_LENGTH_A = 0
	{VARIABLE DEBUG_LENGTH_A $horse_store.length} 

	[if]
		[variable]
			name=horse_store.length
			greater_than=0 #Evaluates to true
		[/variable]
		[then]
			#DEBUG_LENGTH_B = 1
			{VARIABLE DEBUG_LENGTH_B $horse_store.length} 
			...
		[/then]
	[/if]
	...
[/event]
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

right, it looks like the retrieval inside the [if] was mistakenly 'forcing' horse_store to exist before checking length. this may have already been fixed in svn, but I'll have to check. thanks
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

looks like the bug was still active. I fixed it in r20193 /trunk/ "fix a bug with array.length side-effects causing empty arrays to increase to size 1"
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Post Reply