Jump to content
Sign in to follow this  
Graz

[Question] How to use public variables properly

Recommended Posts

I've been trying to initiate an an storm by using a public variable as a boolean.

It's for multiplayer, with JIP on a dedicated server. The server handles the probability of a storm occurring and the client executes the effects. It all worked perfectly without the variable, but now it's not returning anything. This is the first time I've use a public or global variable so I'm sure I've just made a rookie mistake! Here's the code:

mission init.sqf:


//Storm pulse
if (isDedicated) then {
[] execVM "weather/storm_pulse.sqf";
};
//Storm
if (!isDedicated) then {
[] execVM "weather/storm.sqf";
};
[/Code]

This is the storm_pulse.sqf

[Code]
//Storm testing
while {true} do {
sleep 120;
Grazstorm = True;
publicVariable "Grazstorm";
};
[/Code]

And the loop and call in storm.sqf

[u]This isn't the whole code, just the relevant parts[/u]

[Code]
[] spawn {
_delay = 3;
sleep 0.01;
while {true} do {
if (Grazstorm = true) then {
_delay setovercast 0.9;
_delay setrain 1;
_delay setfog bis_fog;
sleep _delay ;
};
};
};
//It's called again here
while {true} do {
if (Grazstorm = true)
then {
//A metric ton of code I've removed
};
sleep 0.2;
};
[/Code]

I have no idea how this isn't working!!! Squint didn't have any errors and the effects worked perfectly until I put in these checks. Does anyone know where I've ballsed up?

Share this post


Link to post
Share on other sites
while {true} do
{    
         if ([color=#ff0000]Grazstorm[/color])  then 
        {             
           //A metric ton of code I've removed    
        };    
sleep 0.2;
};

Edited by Iceman77

Share this post


Link to post
Share on other sites

Edit: forgot to say thanks for posting back :)

Is that different from = true? Or is it just a lot cleaner?

Share this post


Link to post
Share on other sites

No it shouldn't. What I posted is to check bool on a variable.

---------- Post added at 22:49 ---------- Previous post was at 22:46 ----------

If you wanted to check for a false variable then use

If (!Grazstorm) Then { ... do some shit ...};

If you wanted to see if the variable (exists) then you can use

 If (IsNil "Grazstorm") Then {hint "the variable doesn't exist"} Else {Hint "The variable has been set and it exists"};

---------- Post added at 22:54 ---------- Previous post was at 22:49 ----------

= sets/assigns (w/e) a variables value.

If you wanted to compare then use ==

Edited by Iceman77

Share this post


Link to post
Share on other sites

= is assign value

== is equal to

If you'd had == the if condition would be

if (true == true) then {
//
};

Since your variable is a Boolean. Hence you only need to write the variable since you're checking its value.

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  

×