can type effect main program globals?
BlitzMax Forums/BlitzMax Beginners Area/can type effect main program globals?
| ||
In my main I have a global,say thisglobal menutimer=millisecs()+5000 Can I have a Function type reload menutimer?Somethig like this? Tmenu.reloadtimer I can't figure out how,since you can have a global menutimer in the types and in main.I guess I could use global Types in my main?Use this Tmenu.menutimer=millisecs()+5000 Did I just answer my own question? Thanks, mudcat |
| ||
remove the Tmenu before .menutimer. This is not needed as the globel is not a global of this type but a global of the program |
| ||
I'm sorry, I did not word my question right.I want a type to effect my main global.I was asking how. Thanks, mudcat |
| ||
your code is already correct. Only the scope you try to access it (Tmenu.menutimer) does not exist because the global is not defined within the type but in the program itselfglobal menutimer = millisecs() type trala method reloadtimer() menutimer = millisecs() end method end type local a:trala = new trala a.reloadtimer |
| ||
Thanks for the reply, Using your reply,I also found out that types can call main functions too.This is starting to get interesting. thanks, mudcat |
| ||
You may also find this interesting:Global menutimer Type trala Global menutimer Method reloadtimer() menutimer = 10 'set the types global .menutimer = 999 'set the 'global' global End Method End Type Local a:trala = New trala a.reloadtimer Print menutimer Print a.menutimer |
| ||
Thanks, I was wondering about having a global main and a global type with same name. The global-global :) mudcat |
| ||
in addition, if you redefine a global in an extended type, it becomes its own instance seperate of the base type:Global menutimer Type trala Global menutimer Method reloadtimer() menutimer = 10 'set the types global .menutimer = 999 'set the 'global' global End Method End Type Type trala_b Extends trala Global menutimer ' if we didnt override this, then calling it would only set the menutimer on trala Method reloadtimer() menutimer=223 Super.reloadtimer() ' call the base reload EndMethod EndType Local a:trala = New trala Local b:trala_b = New trala_b b.reloadtimer Print menutimer Print a.menutimer Print b.menutimer |