Jump to content

Recommended Posts

Hello again!

 

This is one thing that can always surprise me.

 

The idea is to have combined counter, in this case total_counter. In this example all the player have action to call fn_callFunction.

I'm struggling to make that counter stay same on every player.

 

If computer 1 makes the first call (hint "1") and computer 2 makes the second call (hint "1"), it's still the first call for computer 2.

 

So basicly i'm trying to make it count +1 on every call.

 

If computer 1 makes the first call (hint "1") and computer 2 makes the second call (hint "2")

 

 

This is just a rough example

 

init.sqf

[] execVM "core\function\fn_function.sqf";

fn_function.sqf

total_count = 0;

fn_callFunction = {
    if (total_count == 0) then {
        total_count = total_count +1;
                hint "1";
        }else{
            if (total_count == 1) then {
                total_count = total_count +1;
                                hint "2";
                }else{
                    if (total_count == 2) then {
                        total_count = total_count +1;
                                                hint "3";
                        }
                }
        }
};


player init

this addAction ["Call",{call fn_callFunction}]

I tried different ways for 3 hours and still no results.

publicVariable, setVariable, getVariable, private, isServer, isDedicated

 

Any thoughts?

Share this post


Link to post
Share on other sites
total_count = 0;
publicVariable "total_count";

fn_callFunction =
{
	total_count = total_count + 1;
	publicVariable "total_count";
	str(total_count) remoteExec ["hint",0,false];
};

Assuming you want every player to see the hint after each increment, if no, simply do:

hint str(total_count);//in place of remoteExec line
  • Like 1

Share this post


Link to post
Share on other sites
total_count = 0;
publicVariable "total_count";

fn_callFunction =
{
	total_count = total_count + 1;
	publicVariable "total_count";
	str(total_count) remoteExec ["hint",0,false];
};

Assuming you want every player to see the hint after each increment, if no, simply do:

hint str(total_count);//in place of remoteExec line

 

Thank you jshock.

 

Now that i know where to look at biki, i can see the answer written there as well.

 

Public variables are global variables that are visible on all computers in the network. You can never have true public variables, but you can emulate their behaviour.

The value of a global variable gets broadcasted over the network using publicVariable. After the call of this command the variable will have the same value on all clients. Once you modify the variable though you have to broadcast it manually again with publicVariable.

 

https://community.bistudio.com/wiki/Variables

Share this post


Link to post
Share on other sites

bad, publicVariables + remoteExec naughty don't do that.

remoteExec and remoteExecCall replaced PublicVariables.

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

×