WTF? Globals only in main program??!!

Blitz3D Forums/Blitz3D Beginners Area/WTF? Globals only in main program??!!

Iso(Posted 2004) [#1]
wat does that mean? look at my code ok, i want it to load the image "player.bmp" but in not work:
Repeat

Graphics 640,480,32,1
Color Rnd(0,255),Rnd(100,255),Rnd(50,255)
Rect 0,0,640,480
Global gfx1
Global gfx1=LoadImage("player.bmp")
WaitKey()
End
Stop Until End

why does it not work?


Gabriel(Posted 2004) [#2]
You already declared it Global the first time. You don't need to do it again. From then on you can just use the variable name alone.

I think that's your problem. I really don't get the Stop Until End thing at the end, but I think it's just the double declaration that's the problem.


puki(Posted 2004) [#3]
For starters, put the repeat after the Graphics comand - put the first global before the repeat and then remove the second global (just the word).

Graphics 640,480,32,1

Global gfx1

Repeat
Color Rnd(0,255),Rnd(100,255),Rnd(50,255)
Rect 0,0,640,480
gfx1=LoadImage("player.bmp")
WaitKey()
End
Stop Until End


TomToad(Posted 2004) [#4]
I'd recommend also putting the LoadImage command outside the Repeat loop. No need to load it every loop as well as causing a memory leak.


VIP3R(Posted 2004) [#5]
Stop Until End ???

You don't need the Repeat - Until loop in that example as you end the program after one cycle anyway.


jfk EO-11110(Posted 2004) [#6]
Your code, Iso:

Graphics 640,480,32,1
Color Rnd(0,255),Rnd(100,255),Rnd(50,255)
Rect 0,0,640,480
Global gfx1
Global gfx1=LoadImage("player.bmp")
WaitKey()
End
Stop Until End

is really entertaining, but don't feel offended. You just hack your way trough it by trial and error, and that's ok. Here is my version of your Code. I think you want to display the image you just loaded? because Loading does not automaticly display it.

Graphics 640,480,32,1 
setbuffer backbuffer() ; direct gfx operations to backbuffer

Global gfx1 
gfx1=LoadImage("player.bmp") 

while not keyhit(1) ; loop until someone presses ESC
 Color Rnd(0,255),Rnd(100,255),Rnd(50,255) 
 Rect 0,0,640,480 ,1
 drawimage gfx1, mousex(), mousey()
 Flip ; swap workbuffer (backbuffer) and visible buffer (frontbuffer)
wend
End