GLBasic forum

Main forum => GLBasic - en => Topic started by: bricky91 on 2008-Feb-21

Title: FOR problem
Post by: bricky91 on 2008-Feb-21
hi guys, i have aproblem with this code


Code (glbasic) Select
LOADSPRITE "lana.bmp",0

GLOBAL n_lana
DIM lanax[5]
DIM lanay[5]
DIM lana_xscale[5]
DIM lana_yscale[5]
DIM lana_exists[5]
DIM lana_ricrea[5]

GLOBAL click







WHILE TRUE
GOSUB muovi
SHOWSCREEN
WEND




// ------------------------------------------------------------- //
// ---  MUOVI  ---
// ------------------------------------------------------------- //
SUB muovi:

MOUSESTATE mx,my,b1,b2



IF b1=FALSE
click=0
ENDIF


IF n_lana<4
n_lana=n_lana+1
lanax[n_lana]=RND(640)
lanay[n_lana]=RND(480)
lana_xscale[n_lana]=1
lana_yscale[n_lana]=1
lana_exists[n_lana]=1
lana_ricrea[n_lana]=0
ENDIF


FOR i=1 TO n_lana

lana_yscale[i]=lana_xscale[i]

IF lana_exists[i]=1
IF lana_xscale[i]>0
IF b1 AND click=0
IF mxlanax[i]-32 AND mylanay[i]-32
lana_xscale[i]=lana_xscale[i]-0.1
ENDIF
click=1
ENDIF

ELSE

lana_exists[i]=0
lana_ricrea[i]=120

ENDIF
ENDIF


IF lana_exists[i]=0
lana_ricrea[i]=lana_ricrea[i]-1
ENDIF

IF lana_ricrea[i]<0
lana_ricrea[i]=0
lana_exists[i]=1
lana_xscale[i]=1
ENDIF


ZOOMSPRITE 0,lanax[i]-32,lanay[i]-32,lana_xscale[i],lana_yscale[i]


PRINT lana_exists[i],lanax[i],lanay[i]
PRINT lana_xscale[i],lanax[i]-64,lanay[i]-64

NEXT


DRAWRECT mx,my,10,10,RGB(255,255,255)


ENDSUB // MUOVI
i want 4 sheeps(in this code there isn't any sheep) that go around the scrreen, and i made it... it works fine... now i want the wool of the sheeps, so in the game you have to shear the sheeps... here begins the problem... with the code i wrote, i can shear only the first sheep, and when the first sheep has no wool, i can shear the second... but i don't want to shear the sheeps in order... how can i modify the code so that i can shear the sheep i want? i think the probelm is in the FOR statement... but i can't correct the code...
Title: FOR problem
Post by: Schranz0r on 2008-Feb-21
Use Types and FOREACH... thats easier
Title: FOR problem
Post by: Kitty Hello on 2008-Feb-21
It's hard to tell, since neither your variable names, nor your comments make any sense to us.