OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: ModestNovice on 24 Sep 2008, 03:53:00
-
So I have just a few questions on publicVariable
1: does this work? If not, how do I do this properly?
message = "Server globalchat ""This is a test.""";
publicVariable "message";
2: again, I want to know if I do this right.
_veh = _this select 0;
p_veh = _veh;
publicVariable "p_veh";
move_veh = "p_veh setPos (getPos impound)";
publicVariable "move_veh";
-
The first code will work. The question is if it works like you're planning.
It simple set the variable "message" to the string "Server globalchat ""This is a test.""" on all computers.
Same goes to second code. It just transfers the content of the variable, and don't run code because what is code and what is a string?
-
ahhhhhh ok.
So now, basically, how do I run the content of the publicVariable?
basically like for my first code.
I would just like on everyones computer to say:
"This is a message."
is basically something like.
message = "Server globalChat ""This?""";
publicVariable "message";
Server globalChat format ["%1", message];
-
You need some way to trigger the change on the clients. So you can do this a couple of ways. The newest way is to use addpubliceventhandler (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a#848)
I'm just going through some of this myself but basically once you run publicvariable you can catch that change in variable through the APEH. I'm just learning myself here and I'm sure one of the smarter guys will chime in eventually. :D
-
i am trying to avoid that as to in some of my script I have just one simple message like "%1 was Arrested.", and I dont want to create a publicVariableEventHandler just for that.
Although, is it possible to do one publicVariableEventhandler, and just have the server globalChat whatever is passed into it?
like:
message = [];
"message" addPublicVariableEventHandler
{
call compile format ["Server globalChat %1", (_this select 0)];
};
message = [format["%1 was arrested.", _civ]];
publicVariable "message";
-
That is exactly the intention. The only other way to do simply is using triggers. At least with this method you can change the message repeatedly and broadcast it out when you want.
-
righto :)
Thanks for help you two :good:
-
You are using dynamic code creation quite unnecessarily (call compile format). You are also using the wrong parameter in the event handler, since "_this select 0" is the name of the variable that was publiced and "_this select 1" contains the new value:
"message" addPublicVariableEventHandler
{
Server globalChat ((_this select 1) select 0);
};
message = [format ["%1 was arrested.", _civ]];
publicVariable "message";
-
right!
!Dedgummit DaChevs!
THANKS SPOON!
I really want learn how to do this properly
-----------------------------------------------------------------
Ok, now on to final question.
How can I pass more than 2 values into the PV?
could I do something like this?
_trade_player = ((_this select 1) select 0);
_values = ((_this select 1) select 1);
_a = _values select 0;
_item = _values select 1;
_num = _values select 2;
my_values = [_amount, _item, _number];
send_item = [_civ, my_values];
publicVariable "send_item";
-
Yes, since 1.09 all kinds of variables can get transmitted.
-
sweet!
Thanks :D