Jump to content
  • 0

Share global variable from server to client


Sandbird

Question

I need to set a global variable in a unit on the server. How can i check that variable after on the client side ?

Its for a bot i want to have a 'dialog' with. I need to access the 'name' of the bot.

On my server i got:

_sideGroup = createGroup WEST;
_unit_4 = objNull;
if (true) then
{
  _this = _sideGroup createUnit ["Graves_Light_DZ", [5101.4746, 2550.7922, 0.36117637], [], 0, "CAN_COLLIDE"];
  _unit_4 = _this;
  _this setDir -29.416721;
  _this setVehicleVarName "botunit";
  botunit= _this;
  _this setUnitAbility 0.60000002;
  if (true) then {_sideGroup selectLeader _this;};
    _this addEventHandler ["HandleDamage", {false}];
    _this allowDammage true;
};

and on the client side i want to do this:

    if ((!isNull cursorTarget) && (player distance botunit<= 5)) then {    
           .....
    };

I've tried this but it doesnt recognize 'botunit'.

 

Anyone knows ?

 

Aslo....how will the 'bot' send side messages to the player ?

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

yeah, probably cant...

still have a global variable issue though...Its not working on another level now. Its a client side problem.

I got a script that loads on addaction. That script has some objects spawning like this:

[] spawn {[botunit,3] call target_spawner};

The target_spawner is a function, compiled first of course, but inside it, it should take a global variable and add +1 to it...like this

bots = bots + 1;
alive = alive + 1

this global variable should be used now outside, in the script that called the function in a hint box like:

hintsilent format["Bots: %1/%2 Score: %3", bots, alive, _score];

The hint is inside a while statement with a sleep 1 at the end.....but ......the global value is not updating....

I've set the variables to 0 in the variables.sqf, and i see 0 when the hint appears...but why isnt it updating ?

In a nutshell

 

player -> addaction ---> script.sqf

                                      script.sqf ---> call target_spawner

                            target_spawner ---> update values bots, alive

                                      script.sqf ---> while{true}---> show values  bots, alive

Link to comment
Share on other sites

  • 0

Ok i kinda managed to make it work...only that i am stuck to a weird point.

I've set some global variables to some objects on the server side, and they work fine (checked with diag_log) ( i publicvariabled them :P)

But when it reaches the point the objects to run a script (file is on the client side)....that damn thing is not firing up.

 

t11 is the global variable of the object
_ran1 is a random value...(i've set it to 100 for testing purposes)
tar_hit.sqf all it does is adds a counter (hit=hit+1) basically.

if(_ran1 > 50)then{t11 addEventHandler ["hit", {[t11,5] execVM "custom\tar_hit.sqf"}];};

Does this look wrong ? I've added a diag_log format [ "OBJ:%1", t11];  before the last curly end and it did echo t11, so it is grabbing the object.

But adding a test diag_log at the top of the file,  in the tar_hit.sqf brings nothing oO

Its not running tar_hit and i dont understand why

 

 

edit:  Ok i know why now.......stupid server objects vs client objects....

Link to comment
Share on other sites

  • 0

Hey is there a way to set the scope on a variable? Or is it just the underscore? I have one that I can't seem to reference from anywhere. All client side (mission)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...