OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: ModestNovice on 24 Sep 2008, 03:53:00

Title: publicVariable questions
Post 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?
Code: [Select]
message = "Server globalchat ""This is a test.""";
publicVariable "message";

2: again, I want to know if I do this right.
Code: [Select]
_veh = _this select 0;
p_veh = _veh;
publicVariable "p_veh";
move_veh = "p_veh setPos (getPos impound)";
publicVariable "move_veh";
Title: Re: publicVariable questions
Post by: i0n0s on 24 Sep 2008, 04:09:39
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?
Title: Re: publicVariable questions
Post by: ModestNovice on 24 Sep 2008, 04:12:49
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:
Code: [Select]
"This is a message."

is basically something like.
Code: [Select]
message = "Server globalChat ""This?""";
publicVariable "message";
Server globalChat format ["%1", message];
Title: Re: publicVariable questions
Post by: hoz on 24 Sep 2008, 04:19:32
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
Title: Re: publicVariable questions
Post by: ModestNovice on 24 Sep 2008, 04:21:54
 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:
Code: [Select]
message = [];
"message" addPublicVariableEventHandler
{
call compile format ["Server globalChat %1", (_this select 0)];
};



Code: [Select]
message = [format["%1 was arrested.", _civ]];
publicVariable "message";
Title: Re: publicVariable questions
Post by: hoz on 24 Sep 2008, 04:40:16
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.
Title: Re: publicVariable questions
Post by: ModestNovice on 24 Sep 2008, 05:26:21
righto :)

Thanks for help you two  :good:
Title: Re: publicVariable questions
Post by: Spooner on 24 Sep 2008, 12:05:59
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:
Code: (at init) [Select]
"message" addPublicVariableEventHandler
{
    Server globalChat ((_this select 1) select 0);
};

Code: (to send a message) [Select]
message = [format ["%1 was arrested.", _civ]];
publicVariable "message";
Title: Re: publicVariable questions
Post by: ModestNovice on 24 Sep 2008, 23:13:19
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?

Code: [Select]
_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;



Code: [Select]
my_values = [_amount, _item, _number];

send_item = [_civ, my_values];
publicVariable "send_item";

Title: Re: publicVariable questions
Post by: i0n0s on 25 Sep 2008, 02:11:02
Yes, since 1.09 all kinds of variables can get transmitted.
Title: Re: publicVariable questions
Post by: ModestNovice on 25 Sep 2008, 02:29:33
sweet!

Thanks  :D