Page 1 of 1

InstallEventHandler question regarding the function

Posted: Thu Feb 25, 2021 10:28 am
by Bugala
I have this:

Code: Select all

InstallEventHandler({OnKeyDown = Function(msg) Self:HandleOnKeyDown(msg) EndFunction})
This works fine in sense that the right function gets executed.

However, I am having one problem with the function that I am not sure what is the root reason or how to fix it.

Thing is, I have something like:

Code: Select all

function OOP:HandleOnKeyDown(msg)
debugprint(self.myvariable)
endfunction
And problem is that it seems I don't seem to able to update this variable.

For at start I set this myvariable to "none" and then elsewhere in code I do:

Code: Select all

self.myvariable = "something"
and it seems to have that "something" where ever else in that OOP I try it, but when I i push a key down, it keeps debugprinting "none".

As far as I have understood, this system I am using on InstallEventHandler should make it to call the function dynamically, but based upon it not working as expected, is it then saving it somehow into its current state and hence it keeps thinking that myvariable is "none" instead of "something"?

Re: InstallEventHandler question regarding the function

Posted: Sun Mar 28, 2021 12:33 pm
by lazi
Not sure I understand your problem, but AFAIK self has meaning only inside the oop function.

If you need to update OOP: function's self.myvariable outside the OOP: function then you should call the variable OOP.myvariable.

If you are familiar with that, please try to rephrase the problem.

Re: InstallEventHandler question regarding the function

Posted: Sun Mar 28, 2021 12:50 pm
by Bugala
Oh yeah, didnt update here. I actually got my problem solved. In the end it appears I had made a direct call to the OOP instead of OOP Instance, and that's why it didn't work.

So the example I was explaining here that I thought didn't work, actually did work.

But thanks for taking a look anyway.