Bug or my fault? (types related)

Blitz3D Forums/Blitz3D Beginners Area/Bug or my fault? (types related)

And now the same snippet of code to see why if some instruction are inside a function they don't work...(millisecs()
Here the code with the function: (the one that don't work)
Graphics 640,480,32,2

Global bullet_image=LoadImage("bullet1.bmp")
Global bomb_image=LoadImage("bullet3.bmp")
Global jet_image=LoadAnimImage("jet-strip1.bmp",42,54,0,7)
Global jet.main_jet
Global assex
Global assey
Global joypad
Global x=320
Global y=240
MidHandle jet_image
MidHandle bomb_image
MidHandle bullet_image
Global missile.bullet	






Type bullet
	Field immagine
	Field positionx
	Field positiony
	Field potenza
	Field velocita
	Field durata
End Type

Type main_jet
	Field posizionex
	Field posizioney
	Field immagine
	Field potenza
	Field resistenza
	Field velocita
End Type

Function load_mainjet(image)
	jet.main_jet=New main_jet
	jet\posizionex=320
	jet\posizioney=240
	jet\immagine=image
	jet\potenza=1
	jet\resistenza=20		;successivamente si applicheranno dei modificatori (power-up)
	jet\velocita=1
End Function

Function crea_proiettile(immagine,speed,power,posx,posy,lunghezza)
	missile.bullet=New bullet
	missile\immagine=immagine
	missile\positionx=posx
	missile\positiony=posy
	missile\potenza=power
	missile\velocita=speed
	missile\durata=lunghezza
End Function


Function spara_proiettili()
	If hi_score<=100	;un rudimentale sistema di power-up
		crea_proiettile(bullet_image,6,1,jet\posizionex-10,jet\posizioney-20,50)	;proiettilenormale
	EndIf
	If hi_score >100	;se il punteggio e superiore a 100 crea un altro proiettile...
						;posso usare un'altra condizione(aver raccolto un power-up)
						;aumentare il danno ecc ecc
		crea_proiettile(bullet_image,6,1,jet\posizionex-10,jet\posizioney-20,50)	;proiettilenormale
		crea_proiettile(bullet_image,6,1,jet\posizionex+10,jet\posizioney-20,50)	;proiettilenormale
	EndIf
End Function


Function muovi_proiettile()

	For missile.bullet = Each bullet
		missile\durata = missile\durata-1
		

		If missile\durata=<0
			Delete missile
		Else
			missile\positionx = missile\positionx ;This does nothing.
			missile\positiony = missile\positiony-missile\velocita
			counter = counter+1 ;This doesn't appear to be used.
			DrawImage (missile\immagine,missile\positionx,missile\positiony)
		EndIf		
	Next
End Function

;M A I N 
load_mainjet(jet_image)

While Not KeyHit(1)=True
SetBuffer BackBuffer() : Cls
joybutton1=JoyHit(1)
joybutton2=JoyHit(2)
prova()
If jetdistrutto=False	;se il jet non e stato distrutto spari,altrimenti non spari ^^
	If joybutton1=True		;se premo il tasto sinistro del mouse
		spara_proiettili()
	EndIf
	If joybutton2=True ;se premo il tasto destro del mouse
		crea_proiettile(bomb_image,4,5,jet\posizionex,jet\posizioney-20,30)	;proiettile + potente (bomba)
	EndIf
EndIf

muovi_proiettile()

Flip True
Wend

Function prova()
For jet.main_jet=Each main_jet
assex=JoyX()*2
assey=JoyY()*2
joypad=JoyX()
jet\posizionex=jet\posizionex+assex
jet\posizioney=jet\posizioney+assey
If jet\posizionex => 630 Then jet\posizionex=jet\posizionex-2
If jet\posizionex <= 10 Then jet\posizionex=jet\posizionex+2
If startmov=0 Then fotogramma=3
DebugLog timer
DebugLog counter
If joypad=0 And startmov=1	;no left or right direction pulled and no animation started
	If MilliSecs()> counter+50
		counter=MilliSecs()
		If fotogramma > 3
			current_frame=fotogramma
			fotogramma=current_frame-1
			If fotogramma=3Then fotogramma=3:startmov=0	;reset the anim to not started...
		EndIf
		If fotogramma < 3
			current_frame=fotogramma
			fotogramma=current_frame+1
			If fotogramma=3 Then fotogramma=3:startmov=0	;reset the anim to not started...
		EndIf
	EndIf
EndIf

If joypad=1 Then 	;if joypad pull right
	startmov=1
	If MilliSecs() > timer + 150
		timer=MilliSecs()
		current_frame=fotogramma
		fotogramma=current_frame+1
		If fotogramma => 6 Then fotogramma=6
	EndIf
EndIf

If joypad=-1 Then	;if joypad pull left
	startmov=1
	If MilliSecs() > timer + 150
		timer=MilliSecs()
		current_frame=fotogramma
		fotogramma=current_frame-1
		If fotogramma < 0 Then fotogramma=0
	EndIf
EndIf

DrawImage jet_image,jet\posizionex,jet\posizioney,fotogramma		
Next
End Function


Now here's the code that work (the one without the function but with the EXACT instruction of the previous function...)
Graphics 640,480,32,2

Global bullet_image=LoadImage("bullet1.bmp")
Global bomb_image=LoadImage("bullet3.bmp")
Global jet_image=LoadAnimImage("jet-strip1.bmp",42,54,0,7)
Global jet.main_jet
Global assex
Global assey
Global joypad
Global x=320
Global y=240
MidHandle jet_image
MidHandle bomb_image
MidHandle bullet_image
Global missile.bullet	






Type bullet
	Field immagine
	Field positionx
	Field positiony
	Field potenza
	Field velocita
	Field durata
End Type

Type main_jet
	Field posizionex
	Field posizioney
	Field immagine
	Field potenza
	Field resistenza
	Field velocita
End Type

Function load_mainjet(image)
	jet.main_jet=New main_jet
	jet\posizionex=320
	jet\posizioney=240
	jet\immagine=image
	jet\potenza=1
	jet\resistenza=20		;successivamente si applicheranno dei modificatori (power-up)
	jet\velocita=1
End Function

Function crea_proiettile(immagine,speed,power,posx,posy,lunghezza)
	missile.bullet=New bullet
	missile\immagine=immagine
	missile\positionx=posx
	missile\positiony=posy
	missile\potenza=power
	missile\velocita=speed
	missile\durata=lunghezza
End Function


Function spara_proiettili()
	If hi_score<=100	;un rudimentale sistema di power-up
		crea_proiettile(bullet_image,6,1,jet\posizionex-10,jet\posizioney-20,50)	;proiettilenormale
	EndIf
	If hi_score >100	;se il punteggio e superiore a 100 crea un altro proiettile...
						;posso usare un'altra condizione(aver raccolto un power-up)
						;aumentare il danno ecc ecc
		crea_proiettile(bullet_image,6,1,jet\posizionex-10,jet\posizioney-20,50)	;proiettilenormale
		crea_proiettile(bullet_image,6,1,jet\posizionex+10,jet\posizioney-20,50)	;proiettilenormale
	EndIf
End Function


Function muovi_proiettile()

	For missile.bullet = Each bullet
		missile\durata = missile\durata-1
		

		If missile\durata=<0
			Delete missile
		Else
			missile\positionx = missile\positionx ;This does nothing.
			missile\positiony = missile\positiony-missile\velocita
			counter = counter+1 ;This doesn't appear to be used.
			DrawImage (missile\immagine,missile\positionx,missile\positiony)
		EndIf		
	Next
End Function

;M A I N 
load_mainjet(jet_image)

While Not KeyHit(1)=True
SetBuffer BackBuffer() : Cls
joybutton1=JoyHit(1)
joybutton2=JoyHit(2)
; here's the SAME EXACT code that was previously inside the function....with the "for...each" for the types also
;**********
For jet.main_jet=Each main_jet
assex=JoyX()*2
assey=JoyY()*2
joypad=JoyX()
jet\posizionex=jet\posizionex+assex
jet\posizioney=jet\posizioney+assey
If jet\posizionex => 630 Then jet\posizionex=jet\posizionex-2
If jet\posizionex <= 10 Then jet\posizionex=jet\posizionex+2
If startmov=0 Then fotogramma=3
DebugLog timer
DebugLog counter
If joypad=0 And startmov=1	;no left or right direction pulled and no animation started
	If MilliSecs()> counter+50
		counter=MilliSecs()
		If fotogramma > 3
			current_frame=fotogramma
			fotogramma=current_frame-1
			If fotogramma=3Then fotogramma=3:startmov=0	;reset the anim to not started...
		EndIf
		If fotogramma < 3
			current_frame=fotogramma
			fotogramma=current_frame+1
			If fotogramma=3 Then fotogramma=3:startmov=0	;reset the anim to not started...
		EndIf
	EndIf
EndIf

If joypad=1 Then 	;if joypad pull right
	startmov=1
	If MilliSecs() > timer + 150
		timer=MilliSecs()
		current_frame=fotogramma
		fotogramma=current_frame+1
		If fotogramma => 6 Then fotogramma=6
	EndIf
EndIf

If joypad=-1 Then	;if joypad pull left
	startmov=1
	If MilliSecs() > timer + 150
		timer=MilliSecs()
		current_frame=fotogramma
		fotogramma=current_frame-1
		If fotogramma < 0 Then fotogramma=0
	EndIf
EndIf

DrawImage jet_image,jet\posizionex,jet\posizioney,fotogramma		
Next
;**********
;as you see it's the same....








;prova()				commented!!! 







If jetdistrutto=False	;se il jet non e stato distrutto spari,altrimenti non spari ^^
	If joybutton1=True		;se premo il tasto sinistro del mouse
		spara_proiettili()
	EndIf
	If joybutton2=True ;se premo il tasto destro del mouse
		crea_proiettile(bomb_image,4,5,jet\posizionex,jet\posizioney-20,30)	;proiettile + potente (bomba)
	EndIf
EndIf

muovi_proiettile()

Flip True
Wend

Now i have tell everything of the problem (the other that i have are related to these two and the error that i have are similar...)