Jump to content
Sign in to follow this  
MrSanchez

AddPublicEventHandler malfunction

Recommended Posts

Hi'yall.

I'm having a problem, and I can't figure it out, i already commented out everything in my init.sqf to make sure the problem is not in there, well here's what I got

on my init.sqf

tvon = false;
"tvon" addPublicVariableEventHandler {hint "hi"};

my TvOn.sqf

_holder = [tvon];
tvon = true;
publicVariable "tvon";
//hint format ["tvon was %1 at first, but then it turned %2",_holder select 0,tvon];

I commented out the hint format to test whether it might not be overwriting the "hi" message, but no message is shown.

and my TV object

this addAction ["Turn on TV","TvOn.sqf", nil, 6, true, true, "", "(_target distance _this) < 2"];

This looks totally legit to me, I have no idea what is causing the EventHandler not to execute.

Share this post


Link to post
Share on other sites

PVEH's are not triggered locally

Multiplayer:

Note that the EH is only fired on clients where the publicVariable command has not been executed, as publicVariable does not change the variable where it has been executed.

Share this post


Link to post
Share on other sites

According to your conclusion, how would I fix this issue then?

Share this post


Link to post
Share on other sites

have a hint for yourself in the script TvOn.sqf. it should be hinting on every other computer

Share this post


Link to post
Share on other sites

I just read, posted by sickboy, 2008

Okay a few facts about PVEH's:[*] When you change a variable on this machine and then publicVariable it, a PVEH hooked to this PV will not fire on this machine (but it will on all the other machines). So history doesn't matter, it simply comes down to "The PVEH will not fire on the machine that updates the variable, and pv's it"[*] To my experience, every single publicVariable action, will be received by other machines PVEH's. Even if you do 100 transactions in a second. Even from multiple machines.[*] By using (_this select 1) inside the PVEH, and not a reference directly to the variable itself, you make sure that you use the value of the variable, as it was at the exact moment of the receive

so I'll go test it with another player, see if he gets the message, if he does I just add a message after the publicVariable line, as it's locally executed anyway.

edit: oops, just read your post, mikie boy, oh well.. i wud've thanked you if I didn't figure it out myself ;P thanks for the effort though.

Share this post


Link to post
Share on other sites

Usually I write a normal function instead and have the PVEH call the function, and then call the function from whoever executed it if needed.

If you're using CBA it's alot easier, CBA EV's are triggered locally.

Share this post


Link to post
Share on other sites

Yeah an example would be nice, also I am using CBA, although never coded using its functions.

Share this post


Link to post
Share on other sites
_holder = [tvon];
tvon = true;
publicVariable "tvon";
hint "hi"; //Since the publicVariableEventHandler does not fire where it is publicVariable'd

Share this post


Link to post
Share on other sites

Yeah I got it working already, but I meant an example of what cuel said, or using CBA's event handlers.

Share this post


Link to post
Share on other sites

CBA is very easy to use once you get a hang of it. Some small examples, created at init:

if (!isDedicated) then {
// called with ["CUL_switchMove", [_unit,"SwitchMoveAnim"]] call CBA_fnc_globalEvent;
["CUL_switchMove", {(_this select 0) switchMove (_this select 1)}] call CBA_fnc_addEventHandler;
};

E.g in some addAction script, there would be

_unit = _this select 0;
_caller = _this select 1;
_id = _this select 2;

["CUL_switchMove", [_unit,"zevl6_c0start"]] call CBA_fnc_globalEvent;

Not using CBA I'd do something like this

CUL_switchMove = {
(_this select 0) switchMove (_this select 1);
};


"CUL_switchMovePV" addPublicVariableEventHandler {
_var = _this select 1;
_var call CUL_switchMove;
};

Some other script

//some other script
CUL_switchMovePV = [someUnit,"zevl6_c0start"];
publicVariable "CUL_switchMovePV";
CUL_switchMovePV call CUL_switchMove;

Perhaps not the best examples since you could just write a normal switchMove there but hopefully that explains it a bit :)

Most of the time this is only a problem (for me) when you want a mission to be both listen and dedicated compatible.

Share this post


Link to post
Share on other sites

Well yeah, I want mine to be listen and dedicated compatible, since I made this mission for my realism unit, which will be hosted on the dedi tomorrow.

so what i got right now is:

init.sqf

tvon = false;
"tvon" addPublicVariableEventHandler {script = ["init\untitled.ogv",1.15] spawn bis_fnc_customGPSvideo;};

TvOn.sqf

tvon = true;
publicVariable "tvon";
_script = ["init\untitled.ogv",1.15] spawn bis_fnc_customGPSvideo;

and the addaction on the first post, but thats not a problem,

would this work on dedicated aswell?

Edited by PhonicStudios

Share this post


Link to post
Share on other sites

Init:

//tvon = false; NOT needed 
"tvon" addPublicVariableEventHandler {(_this select 1)  spawn bis_fnc_customGPSvideo};

Addaction:

_unit = _this select 0;
["init\untitled.ogv",1.15] spawn bis_fnc_customGPSvideo;//Execute Locally

//Execute Globally 
if (isMultiplayer) then {
tvon = ["init\untitled.ogv",1.15];
publicVariable "tvon";
};

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  

×