Home   Help Search Login Register  

Author Topic: publicVariable questions  (Read 1868 times)

0 Members and 1 Guest are viewing this topic.

Offline ModestNovice

  • Members
  • *
publicVariable questions
« 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";
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline i0n0s

  • Former Staff
  • ****
Re: publicVariable questions
« Reply #1 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?

Offline ModestNovice

  • Members
  • *
Re: publicVariable questions
« Reply #2 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];
« Last Edit: 24 Sep 2008, 04:21:41 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: publicVariable questions
« Reply #3 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

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
Xbox Rocks

Offline ModestNovice

  • Members
  • *
Re: publicVariable questions
« Reply #4 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";
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: publicVariable questions
« Reply #5 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.
Xbox Rocks

Offline ModestNovice

  • Members
  • *
Re: publicVariable questions
« Reply #6 on: 24 Sep 2008, 05:26:21 »
righto :)

Thanks for help you two  :good:
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: publicVariable questions
« Reply #7 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";
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline ModestNovice

  • Members
  • *
Re: publicVariable questions
« Reply #8 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";

« Last Edit: 24 Sep 2008, 23:46:26 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline i0n0s

  • Former Staff
  • ****
Re: publicVariable questions
« Reply #9 on: 25 Sep 2008, 02:11:02 »
Yes, since 1.09 all kinds of variables can get transmitted.

Offline ModestNovice

  • Members
  • *
Re: publicVariable questions
« Reply #10 on: 25 Sep 2008, 02:29:33 »
sweet!

Thanks  :D
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley