FOR problem

Previous topic - Next topic

bricky91

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...

Schranz0r

Use Types and FOREACH... thats easier
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

It's hard to tell, since neither your variable names, nor your comments make any sense to us.