Jump to content
Sign in to follow this  
crushenator

Need help with variables.

Recommended Posts

I've spent hours now trying to figure out how to use global variables to no avail.

Long story short of what info I'm after is where and how to assign a variable that can be accessed from scripts, triggers, waypoints by all players on a server and can be used as the condition for triggers, units. Anything really.

Below is one attempt i've made to work with a variable.

In this particular instance I've got in the init.sqf (i'm not even sure if i need this)

myVar = 1;

Then I've got a helicopter with an init containing

_mytest = introheli addaction ["Send helicopter away", "mytest.sqf"];

and in mytest.sqf I've got

private ["_heli", "_caller", "_id", "_heligroup"];

_heli = _this select 0;

_caller = _this select 1;

_id = _this select 2;

_heligroup = group (assigneddriver _heli);

Pork = Pork + 1;

if (pork >= 4)

{

_heligroup move getpos woot;

};

So I guess what I figured would happen is if I select the action available on the helicopter 5 times then the helicopter would fly away.

Where am I going wrong here? Thanks for the help

Share this post


Link to post
Share on other sites

First of all you need the -showScriptErrors parameter in your game shortcut to effectively debug scripts. In the case of an undefined variable, you just need to define them at some point before executing a script or command that uses those variables.

A variable is global when it doesn't have the _ in front. If you want it to become public (same for all clients), you have to use the command publicVariable "variablename" every time you want it to update across the net.

Edited by Celery

Share this post


Link to post
Share on other sites
I've spent hours now trying to figure out how to use global variables to no avail.

Long story short of what info I'm after is where and how to assign a variable that can be accessed from scripts, triggers, waypoints by all players on a server and can be used as the condition for triggers, units. Anything really.

Below is one attempt i've made to work with a variable.

In this particular instance I've got in the init.sqf (i'm not even sure if i need this)

myVar = 1;

Then I've got a helicopter with an init containing

_mytest = introheli addaction ["Send helicopter away", "mytest.sqf"];

and in mytest.sqf I've got

private ["_heli", "_caller", "_id", "_heligroup"];

_heli = _this select 0;

_caller = _this select 1;

_id = _this select 2;

_heligroup = group (assigneddriver _heli);

Pork = Pork + 1;

if (pork >= 4)

{

_heligroup move getpos woot;

};

So I guess what I figured would happen is if I select the action available on the helicopter 5 times then the helicopter would fly away.

Where am I going wrong here? Thanks for the help

youve never initialized pork for starters...dont really know what else youre going for...also, coding conventions are such that variables never start with an uppercase letter...makes it harder to read for people looking at your stuff

Share this post


Link to post
Share on other sites

Thanks guys just to clarify how I fixed it.

For starters I initialized pork in init.sqf and I also removed all the capitals. I also included a 'then' after the condition portion of the if statement.

I'm used to C++ syntax so didn't put a 'then'

Edited by crushenator

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  

×