Type Inside a Function

BlitzMax Forums/BlitzMax Beginners Area/Type Inside a Function

Hardcoal(Posted 2012) [#1]
when i declare a type inside a Function does it keep existing when the process is out of the function?


Function General()
Local Temp:TList=new TList

End Function


GfK(Posted 2012) [#2]
No. You're talking about the equivalent of static vars, which i think can be achieved by defining the variable in the function as Global, rather than Local.


Yasha(Posted 2012) [#3]
when i declare a type inside a Function does it keep existing when the process is out of the function?


Declaring a type is what you do with the "Type"/"End Type" block. What you have declared there is a variable, into which you have put an instantiated type, or created object.

The terms are not at all interchangeable. This is important.


As for the answer to your question: not in that case, no - clearing it up is what the garbage collector is for. But it would continue existing if something somewhere outside the function still referred to it, because that would mean it was still in use.

To guarantee that it stays in existence thanks to that one reference, GfK is right (as always), you would declare the variable as Global.


Hardcoal(Posted 2012) [#4]
Sure Tnx for the corrections.
You both


therevills(Posted 2012) [#5]
Have a read up on Scope for variables, it'll explain a few things.

Global iAmGlobal:Int = 5

Function Test:Int()
   Local iAmLocal:Int = 10
   For Local i:Int = 0 To 10
       Local innerLocal:Int = 5
   Next
EndFunction


iAmGlobal can be seen by all, iAmLocal can only been seen in Test and innerLocal can only been seen in the For Loop.