GLBasic forum

Main forum => GLBasic - en => Topic started by: bjimenez on 2011-Oct-15

Title: Map not drawn and window closes (with sucess)
Post by: bjimenez on 2011-Oct-15
Hi,

new here, and I'm trying to draw a map of rectangles but I can't seem to get it working. The program does not error, but the window just pops open then closes even though I have the mousewait command there.

it seems to be something with the read command. If I rem out the read and take out the if d=1 line it does draw the boxes and waits for a mouse click. Not sure why the read would cause this though.

Code (glbasic) Select

SETSCREEN 470,500,0


LOCAL array[],x,y,d
DIM array[22][22]

x=10
y=20

// draw border walls
RESTORE map1

FOR r=1 TO 22
FOR c=1 TO 22
READ d
array[r][c]=d
IF d=1
DRAWRECT x,y,20,20,RGB (0,0,255)
    ENDIF
x=x+20
NEXT
x=10
y=y+20
NEXT

SHOWSCREEN
MOUSEWAIT


STARTDATA map1:
    DATA  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    DATA  1,8,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1
    DATA  1,0,1,0,1,0,1,0,1,0,1,1,1,0,1,0,1,0,1,1,1,1
    DATA  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,5
    DATA  1,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,1
    DATA  1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,1
    DATA  1,0,1,0,1,0,0,0,1,0,1,0,1,1,1,1,1,0,1,1,0,1
    DATA  1,0,1,0,1,0,1,1,1,0,1,0,0,1,0,0,0,0,1,1,0,1
    DATA  1,0,1,0,1,1,1,0,1,0,1,1,0,1,0,1,1,1,1,0,0,1
    DATA  1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,1
    DATA  1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,1,0,1,1,1,0,1
    DATA  1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,1,0,1
    DATA  1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1
    DATA  1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1,0,1
    DATA  1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,0,1
    DATA  1,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,1,1
    DATA  1,0,1,0,1,1,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1
    DATA  1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1
    DATA  1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,0,1
    DATA  1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,1
    DATA  1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,1
    DATA  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

ENDDATA
Title: Re: Map not drawn and window closes (with sucess)
Post by: Minion on 2011-Oct-15
You are defining your array as [22][22] which means you can populate elements 0 to 21, 0 to 21.

but your read goes from 1 to 22, so when it hits 22 it blows the array.
Title: Re: Map not drawn and window closes (with sucess)
Post by: bjimenez on 2011-Oct-15
ooooohhh, ok,, got it thanks   :booze: