jbrave
15 years agoChannel Surfer
Global variable contextuality
if in main() I create an object:
it seems that I have to access it via its name:
?obj.value
instead of m.obj, in the main function, but in subroutines or functions called from main, it is available as a global:
sub printvalue()
?m.value
end sub
further, what if I create a global first:
m.test="xyz"
and then create obj
obj=getobject()
It seems that in some circumstances m.test will be available after m.obj is created and in other cirumstances, it seems to disappear. I first encountered this issue when working on the update to a client project that was based on the Deviant ART example project - most of the globals come into existance when
rss=CreateMediaRSSConnection()
I found that in some cases I could not create new globals that would be added to the combined m. list of globals, so I wound up passing lots of information back and forth through various functions, not that there is anything wrong with that. I"m thinking that persistant globals are created at the top level and globals created in subroutines are non-global if a master object like the obj described at the top of this post has been created, but are still global for subs and functions called from the subs and functions where the global was created. That might be a tough sentence to chew on, sorry.
Comments?
- Joel
obj=GetObject()
function Getobject() as object
return
{action:functionname
action2:function2name
variable:"value"}
end function
it seems that I have to access it via its name:
?obj.value
instead of m.obj, in the main function, but in subroutines or functions called from main, it is available as a global:
sub printvalue()
?m.value
end sub
further, what if I create a global first:
m.test="xyz"
and then create obj
obj=getobject()
It seems that in some circumstances m.test will be available after m.obj is created and in other cirumstances, it seems to disappear. I first encountered this issue when working on the update to a client project that was based on the Deviant ART example project - most of the globals come into existance when
rss=CreateMediaRSSConnection()
I found that in some cases I could not create new globals that would be added to the combined m. list of globals, so I wound up passing lots of information back and forth through various functions, not that there is anything wrong with that. I"m thinking that persistant globals are created at the top level and globals created in subroutines are non-global if a master object like the obj described at the top of this post has been created, but are still global for subs and functions called from the subs and functions where the global was created. That might be a tough sentence to chew on, sorry.
Comments?
- Joel