Globals inside Functions

Blitz3D Forums/Blitz3D Beginners Area/Globals inside Functions

boomboom(Posted 2004) [#1]
Is there anyway to get around this? It won't let me create a global inside a function.


Rob Farley(Posted 2004) [#2]
Correct... Create them outside a function. This is normal programming behaviour as far as I'm aware as if your function was called recursivly it would be very messy indeed.


flounder22001(Posted 2004) [#3]
You should just declare all your globals at the start of the program. Why would you be declaring them in a function any way?


boomboom(Posted 2004) [#4]
Well i am loading my models in and globalising the name so i can use them in creation functions, and i just wanted to put them in a function in an include to keep them neat.

i will just not put them inside a function in an include then :)


Stevie G(Posted 2004) [#5]
Why not just declare the model variables as globals

global MyShip
global EnemyShip

and then do what your doing ...

Function LoadStuff()

Myship = loadmesh("Blah")

end function

etc...


Agamer(Posted 2004) [#6]
Thats what I always do!


Curtastic(Posted 2004) [#7]
sometimes the code would be much better structured if you could declare globals inside functions.

It would not get messed up if you call the function twice. But you should never do that.
this works fine
For a=1 To 2
	Local x
	Print x
	x=1
Next