Jump to content
Sign in to follow this  
Mardikas

Problems with if condition and spawning objects

Recommended Posts

Hello everyone,

I'm new to the forum and relatively new to the mission editor.

The problem I can't seem to fix is to find a command that would change the condition from false to true, I've tried code like this:

if (triggeractivated lala) then {this = false} else {this = true}

The code was used to disable a waypoint after a trigger has gone off, (A group patrols and the cycle waypoint is disabled after the tigger).

Another problem was to spawn an object if another object exists (Dynamic base)

For example I will create a field hospital with a probabilty of 50% and the other objects will spawn depending on if the field hospital spawned or not (The condition field will contain something like:

If (NameObj = true) then {this = true} else {this = false}

I know these codes might not make any sense at all, but can anyone help me out with these problems? =) Thanks

Share this post


Link to post
Share on other sites

Condition checks in themselves ARE if-tests, so it can be simplified pretty much as long as the code in the field IS boolean (i.e. doesn't return a boolean variable, but can processed by a bool-check).

The first example... I'm not really sure what you are putting where. Is the if-check in the cycle-waypoints condition field? If so, just set the condition to !triggerActivated lala. I.e. the waypoint will work as long as the trigger hasn't become true. When it has the waypoint won't be able to finish anymore.

I think that for the second case a simple !isNull NameObj in the condition field should do the trick (note though that this stuff is very sensitive in what order the objects are initialized. You might have to change the order of objects in the mission.sqm file manually to make sure the hospital is listed before everything that depends on its existance, or the check won't work as intended. And even then it feels like a volatile solution, where the best way to solve it would probably to spawn the other objects through script to make guarantee it works as intended).

Edited by Inkompetent

Share this post


Link to post
Share on other sites

Try it as it's described in the Biki, that is, make it the subject of a return by placing a "ThisValue = " in front of it.

Share this post


Link to post
Share on other sites

Oh, and also. When editing an object's properties 'this' refers to the object itself rather than for example the spawn/do not spawn 'variable' (in lack of better words) if you are working in the spawn-context. And since a unit is an object and not a boolean variable you can't just make it true or false, but have terminate/spawn through other means.

For waypoints 'this' refers to the unit (group?) owning the waypoint, and not the waypoint itself

Share this post


Link to post
Share on other sites
_condition = false;

if (triggeractivated lala) then {_condition = true};

if (_condition) then
{
      .......
};

Share this post


Link to post
Share on other sites

The !triggeractivated lala works, but not in the way I want it to, there's another waypoint after the cycle waypoint. Using the !triggeractivated just causes the unit to wait at the waypoint. Inserting the !isNull nameobj into the condition doesn't seem to work either... It has a question mark infront of it in the editor as you hover over it with your mouse. I'll try SNKMAN's given code

Thanks for all the replies,

Share this post


Link to post
Share on other sites

Make the trigger type "switch" sync it to the cycle waypoint and the units will continue to the waypoint that is next after the cycle wp once trigger becomes true.

Share this post


Link to post
Share on other sites

I didn't read through the entire thread but I guess someone already mentioned that a if checks for true / false so that you don't have to do if (bool == true) but if (bool)

I just wanted to point out that the code below has a = at the if part. So to the guy who made it, if you ever want to check if two things are equal.

a == b > a is equal to b

a = b > sets the value of a to b.

If (NameObj = true) then {this = true} else {this = false}

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  

×