News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Can a typed variable be global?

Started by Mick Berg, January 30, 2007, 08:30:55 PM

Previous topic - Next topic

Mick Berg

Why can't I declare a typed variable to be global? And how do you pass a typed variable into a Psub? I know it's in the help, but it is discussed in terms of arrays and it's all too much for my small brain. ???
Thanks,
Mick Berg.

kevin

#1
QuoteWhy can't I declare a typed variable to be global?

Typed Variables/Arrays are global by default

QuoteAnd how do you pass a typed variable into a Psub?





Type Pos
x,y,z
EndType


Dim Location as pos
Dim MyOtherLocation as pos

SetGlobalLocation(100,200,300)
print "Values in My Other Location"
Show(Location())


Sync
waitkey
Waitnokey


SetPassedPos(MyOtherLocation(),111,222,333)
print "Values in Location"
Show(MyOtherLocation())





Sync
waitkey
Waitnokey


; This function acts upon the global Location variable and only that variable
Function SetGlobalLocation(x,y,z)
Location.x=x
Location.y=y
Location.z=z
EndFunction

; this function acts upon any passed in Typed Variable of type .POS
Function SetPassedPos(me.pos,x,y,z)
me.x=x
me.y=y
me.z=z
EndFunction


; this function acts a passed in Typed Variable
Function Show(me.pos)
print me.x
print me.y
print me.z
EndFunction



Mick Berg

Thanks Kevin.
I realised the answer to the first question soon after I had posted, but your example on passing into psubs will be very helpful.
Mick.