Jump to content
Sign in to follow this  
gopgop

Global variables

Recommended Posts

I want to have a global variable that will be initiated to false in the init.sqf and then using an addAction it will run a script that will make the variable true.

and then the condition for a unit to go to its waypoint is the global variable becoming true

How would I do this?

i tried doing this:

init.sqf:

startmission = false;

flag pole object:

_nul = this addAction["Start mission","start.sqf"];

start.sqf:

startmission = true;

helicopter waypoint condition:

startmission = true;

Share this post


Link to post
Share on other sites

See better method in post #6. :)

init.sqf:

startmission = false;

flag pole object:

_nul = this addAction["Start mission","start.sqf"];

start.sqf:

_me = _this select 0;
_act = _this select 2;
_me removeAction _act;
startmission = true;
publicVariable "startmission";
hint "Mission started!";

helicopter waypoint condition:

startmission

You were on the right track. :) Only real changes were publiczing the variable so the server knows it too and in the condition where we changed it from assignment to a check. Also removed the action since you didn't need it anymore and added some feedback.

Edited by kylania
fixed

Share this post


Link to post
Share on other sites

Doesn't work. I did like you wrote but when I choose start mission using the scroll wheel nothing happens and the start mission action stays there

Share this post


Link to post
Share on other sites

That's odd, got lazy and it didn't work! I edited the code above and tested and it works. :)

One thing to keep in mind is that a unit will travel TO a waypoint with a condition first but won't consider it "complete" till the condition is true. So to have someone stay where they are at the beginning put the condition waypoint at their vehicle nose or make that a HOLD waypoint and switch it with a trigger instead to kick the mission off. (Trigger with condition of start mission synched to the HOLD waypoint for example)

Share this post


Link to post
Share on other sites

Thank you so much! You really helped me!

Share this post


Link to post
Share on other sites
init.sqf:

startmission = false;

Setting a variable value in the init.sqf will override the change made via the action, for the late joiners (Join In Progress players).

The best option is to check if the variable has been assigned instead of its value, in this situation.

_me = _this select 0;
_act = _this select 2;
_me removeAction _act;
startmission = true;
publicVariable "startmission";
hint "Mission started!";

And within the waypoint condition just check if variable exists:

!isNil { startmission }

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
Sign in to follow this  

×