Eachin loop with array and modifying that array
BlitzMax Forums/BlitzMax Beginners Area/Eachin loop with array and modifying that array
| ||
How do you modify the array with a eachin loop? In the new part I try to write into the array but it does not register it. Is it needed to use the regular for loop for this to work?Graphics 640,480 Type test Field val:Int[] Method New() val = New Int[10] Local cnt=0 For Local i:Int = EachIn val i = cnt cnt=cnt+1 Next End Method Method draw() Local x:Int=100 Local y:Int=100 SetColor 255,255,255 For Local i:Int=EachIn val DrawText i,x,y y=y+15 Next End Method End Type Local t:test =New test While Not KeyHit(KEY_ESCAPE) Cls t.draw() Flip Wend |
| ||
I think the problem might be the fact that it is an int-array, so it is not passed "by reference" (like in an "eachin list"). Best you can do is: For local i:Int = 0 until val.length val[i] = cnt cnt :+ 1 Next bye Ron |
| ||
Thanks. You also showed me how to add with the :+ and shown me that there is a until to be used with the for command. I just started using bmax. Bought the beginners book on ibooks(only 7 euro :)) |