Hold value for future call

What is a simply and fast way to store a value (integer) that can be called by any function at any time?
Thanks

prefix the variable to hold with m.
That sets it global.
m.myvalue=“Hello”

Print m.myvalue

Hello

Thanks, but for some reason when I use m, I get a type mismatch.

x=9
m.cindex=x

Something like this I get type mismatch. I can do m.cindex=9 and check value in print statement and it shows 9, but when I attempt to set it equal to a variable (integer) it shows the m as being invalid. I know it’s something I just don’t understand or am doing it incorrectly.
Thanks

You must be “doing it incorrectly”, though not sure how.

BrightScript Debugger> x=9
BrightScript Debugger> m.cindex=x
BrightScript Debugger> ? m.cindex
 9

Are you assigning any value to “m” as a variable? That’s the only explanation i can think of. Don’t do that, dare not touch it! The variable “m” is a sacred cow.

PS. on side note, here is my guess why the name “M” was chosen:

[upload|2njnQujEzCervpwJQd2yjw==]

“EnTerr” wrote:
Are you assigning any value to “m” as a variable? That’s the only explanation i can think of. Don’t do that, dare not touch it! The variable “m” is a sacred cow.
I think you’re forgetting that there’s two "m"s - the global “m” and the “m” that’s akin to “this” for an object. I suspect that btpoole is mixing them. I don’t think you can get to the global “m” from within a function that is part of an object.

-JT

“renojim” wrote:

“EnTerr” wrote:
Are you assigning any value to “m” as a variable? That’s the only explanation i can think of. Don’t do that, dare not touch it! The variable “m” is a sacred cow.
I think you’re forgetting that there’s two "m"s - the global “m” and the “m” that’s akin to “this” for an object. I suspect that btpoole is mixing them. I don’t think you can get to the global “m” from within a function that is part of an object.

-JT
You can by calling GetGlobalAA().

Hey, thanks! I do recall seeing that, but I’ve never needed it. I come from the school that says globals are bad. I use them sparingly if at all.

-JT

“renojim” wrote:
I think you’re forgetting that there’s two "m"s - the global “m” and the “m” that’s akin to “this” for an object. I suspect that btpoole is mixing them. I don’t think you can get to the global “m” from within a function that is part of an object.
I did not forget that - but in neither of those two cases you’ll get “type mismatch” as mentioned above. m would have to been mutilated somehow first.

A bit to the side, discussion of m: there are not 2 different M’s as such. Rather, on function invocation the local variable m gets pre-set to one of 2 kind of AA’s, depending on how it got called:

BrightScript Debugger> f = function(): return m: end function
BrightScript Debugger> ? f()
port: <Component: roMessagePort>    'outer M

BrightScript Debugger> obj = { g: f } :  ? obj.g()
g: <bsTypedValue: Function>     'M = obj

BrightScript Debugger> h = obj.g :  ? h()
port: <Component: roMessagePort>   'outer M

BrightScript Debugger> ? obj.g(), (obj.g)(), box(obj).g(), box(obj.g)()    'pop quiz

For evil hackers, one can modify it at own risk (e.g. m = GetGlobalAA() at the very beginning of the fn will guarantee m is always “global”, no matter where the function is).