InstallEventHandler question regarding the function

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

InstallEventHandler question regarding the function

Post 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"?
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: InstallEventHandler question regarding the function

Post 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.
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Re: InstallEventHandler question regarding the function

Post 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.
Post Reply