can type effect main program globals?

BlitzMax Forums/BlitzMax Beginners Area/can type effect main program globals?

mudcat(Posted 2005) [#1]
In my main I have a global,say this
global 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


Dreamora(Posted 2005) [#2]
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


mudcat(Posted 2005) [#3]
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


Dreamora(Posted 2005) [#4]
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 itself
global menutimer = millisecs()

type trala
   method reloadtimer()
      menutimer = millisecs()
   end method
end type

local a:trala = new trala
a.reloadtimer



mudcat(Posted 2005) [#5]
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


Beaker(Posted 2005) [#6]
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



mudcat(Posted 2005) [#7]
Thanks,
I was wondering about having a global main and a global type with same name.
The global-global :)

mudcat


gman(Posted 2005) [#8]
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