Jump to content
Sign in to follow this  
delta99

Public Variables in Event Handlers

Recommended Posts

Is it possible to set public variables in an event handler? It doesn't seem to work for me. Any setting of a public variable in an event handler is not picked up in another event handler.

If this is not possible, what is a decent method of setting a variable? Anyone have any ideas?

Share this post


Link to post
Share on other sites

Good question. I wouldn't know any reason why they shouldn't thought. I have never used PV's in EH's :-)

Could you post your code and findings somewhat more specific?

Share this post


Link to post
Share on other sites

Basically what I'm trying to do is only execute code in an event handler conditionally on a public variable so I have something like:

if (publicVariable != 1) then {

do something;

};

it doesn't seem to matter whether I have that publicVariable assigned to 1 or anything else or never assigned. It never executes the contents of the if block.

I also tried:

if (isnil "publicVariable") {

do something;

};

and that doesn't work either. The isnil never returns true even when the variable is never used anywhere else.

Very odd.

Share this post


Link to post
Share on other sites
Basically what I'm trying to do is only execute code in an event handler conditionally on a public variable so I have something like:

if (publicVariable != 1) then {

do something;

};

it doesn't seem to matter whether I have that publicVariable assigned to 1 or anything else or never assigned. It never executes the contents of the if block.

I also tried:

if (isnil "publicVariable") {

do something;

};

and that doesn't work either. The isnil never returns true even when the variable is never used anywhere else.

Very odd.

If you attempt to compare a variable that has not been assigned it will always return false. And the reason I couldn't detect this yet is that in my event handler they were firing so fast and likely at the same time that they all hit the variable check before it was set later on.

The isnil is also working now that my example code is written a little bit better and I'm controlling how the events are kicked off.

In otherwords, it looks as though public variables work in event handlers no problem as they should be expected to.

Share this post


Link to post
Share on other sites

Well, I would assume that the publicVariable needs time to be picked up by other clients.

So, you can't expect that the instant you issue the command, the clients will have the results of the variable. Nor can you assume you know how long it will take for the variable to reach all clients.

I believe there are some exceptions dealing with the briefing, but I don't remember the specifics. I don't think init events fire until after the briefing anyway though.

Share this post


Link to post
Share on other sites

Actually when I wrote public variable I actually meant global variable. This was all tested in single player so wasn't dealing with real "public" variables I expected to know the value of on various client machines in MP.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×