Page 1 of 1

Local question

Posted: Thu Mar 08, 2012 1:55 am
by djrikki
Hi,

This piece of code results in 78 being displayed by debugprint on each re-iteration of the For/Next loop.

Code: Select all

	    Local a, yoffset = 62
	    
	    If appsdownloaded[0][8] > 0
		    For a = 0 to appsdownloaded[0][8] - 1
		        ; Userdata: pass local and remote archive data to the function called
		            debugprint( 78 + (yoffset * a) )
		        MakeButton(a+1, #SIMPLEBUTTON, 672,78 + (yoffset * a), 110, 40, evtfunc, { appsdownloaded[a+imagepage][3], appsdownloaded[a+imagepage][4] })
		    Next
		EndIf
However if I drop the yoffset = 62 on to a separate line, like so:

Code: Select all

	    Local a, yoffset
	    yoffset = 62
	    
	    If appsdownloaded[0][8] > 0
		    For a = 0 to appsdownloaded[0][8] - 1
		        ; Userdata: pass local and remote archive data to the function called
		            debugprint( a )
		            debugprint( 78 + (yoffset * a) )
		        MakeButton(a+1, #SIMPLEBUTTON, 672,78 + (yoffset * a), 110, 40, evtfunc, { appsdownloaded[a+imagepage][3], appsdownloaded[a+imagepage][4] })
		    Next
		EndIf
The calculation yoffset * a --> will now be perform on each iteration.

If've seen this bug a few times on occasion, I always thought it was possible to specify a multitude of local variables and initiate them with a value(s) on the same line?
Perhaps however I am wrong? I also tried giving 'a' a value of zero, but this just returned '78' all the way through as well.

Re: Local bug

Posted: Thu Mar 08, 2012 6:38 am
by jalih
djrikki wrote:I always thought it was possible to specify a multitude of local variables and initiate them with a value(s) on the same line?

Code: Select all

Local a, yoffset = 62
=> a = 62, yoffset = Nil

Code: Select all

Local a, yoffset = 62, 10
=> a = 62, yoffset = 10