array out of bounds, why??
Blitz3D Forums/Blitz3D Beginners Area/array out of bounds, why??
| ||
I dont know what is wrong in my code. After 2 hours trying to fix it, I preffer post here for if somebody can found any bug or for what reson bilt3D says "array index out of bounds" thanks Graphics 640,480,16,2 Global cu ; size square Global rej ;separation 2 pinxels if grid exis Global cx Global zx Global zy cu = 4: rej =2 zx=107 zy=78 Dim zoom%(zx,xy) ;;MAIN LOOP;; While Not KeyDown(1) makegrid() Wend End ;;END;; Function makegrid() Cls x1=0 :x2=cu y1=0 :y2=cu For x=1 To zx y1=0 :y2=cu For y=1 To zy If grid=True Then If zoom%(x,y) = 0 Then Color 30,30,30 Rect x1,y1,x2,y2,1 EndIf If grid=False Then Color 0,0,0 EndIf If zoom%(x,y)=1 Then Color 255,255,155 Rect x1,y1,x2,y2,1 EndIf y1=y1+cu+rej Next x1=x1+cu+rej Next End Function |
| ||
Your messing about with the loop variable, inside the loop:y1=y1+cu+rej |
| ||
To further on that. Your probably changing the value of y1 to something greater than the maximum dimension of the array. Because in a FOR/NEXT the condition is evaluated at the beginning of the loop and follows through, any changes you make to the FOR/NEXT variable won't be looked at, at the end of the loop. Use a REPEAT/UNTIL loop if you wish it to happen that way. |
| ||
Here's your problem:zx=107 zy=78 Dim zoom%(zx,xy) |
| ||
Here's your problem: zx=107 zy=78 Dim zoom%(zx,xy) yeaaaahhhh! that is teh problem! a "x" must be a "z" my glases was dirty lol now works thanks a lot:):):) Graphics 640,480,16,2 Global cu ; size square Global rej ;separation 2 pinxels if grid exists Global cx Global zx Global zy cu = 4: rej =2 grid = True zx = 60 zy = 50 SetBuffer BackBuffer() Dim zoom%(zx,zy) ;;MAIN LOOP;; While Not KeyDown(1) Cls makegrid() Flip Wend End Function makegrid() For x=1 To zx For y=1 To zy zoom%(x,y)=Rand(0,1) Next Next x1=0 :x2=cu y1=0 :y2=cu For x=1 To zx y1=0 :y2=cu For y=1 To zy If grid=True Then If zoom%(x,y)=0 Then Color 30,130,30 Rect x1,y1,x2,y2,1 EndIf If grid=False Then Color 0,0,0 EndIf If zoom%(x,y)=1 Then Color 255,255,155 Rect x1,y1,x2,y2,1 EndIf y1=y1+cu+rej Next x1=x1+cu+rej Next Delay 100 End Function |
| ||
A-hem, erm, yeah, i totally saw that. I knew Floyd was around the corner so i though i'd give him this one :o) Cause it's christmas. |
| ||
Man, Ross! another mistake? what's happening to you? :DDD |
| ||
Ok Ross C Thank you very much :) |
| ||
:o) |
| ||
Its probably better that you rename your variables so there easier to understand. I think you even ended up confusing yourself with the names of these :) |