Home   Help Search Login Register  

Author Topic: Syntax Question - Conditionals, Condition of Presence  (Read 3600 times)

0 Members and 1 Guest are viewing this topic.

Offline syrion

  • Members
  • *
I have three objects, only one of which I would like to appear.  I tried to set it up like this:

obj1 - Probability 33%, condition true
obj2 - Probability 66%, condition !(alive obj1)
obj3 - Probability 100%, condition !(alive obj1) && !(alive obj2)

This won't work at all.  None of them spawn.  What gives?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Syntax Question - Conditionals, Condition of Presence
« Reply #1 on: 04 Jul 2009, 15:45:38 »
This method will only place obj1 33% of the time and never place obj2/3. Thus, 66% of the time, you see nothing at all appearing.

If an object does not spawn then it isn't dead or null (not alive). Rather, it doesn't exist (value is nil), so those conditions will be seen as errors and obj2/3 will never appear. Also, to get this to work and also to get an even probability spread, the second object should have a probability of 50% in the condition, not 66% in the probability.

obj1 - Probability: 33%, condition: true
obj2 - Probability: 100%, condition: (isNil "obj1") && (random 1 < 0.5)
obj3 - Probability: 100%, condition: (isNil "obj1") && (isNil "obj2")

Not 100% sure about this, but if you still have problems:

Due to the fact that you have to wait for the earlier objects to be created before you can tell if the later objects should be placed, obj1 must be the first one in the mission.sqm and obj3 must be the last one in the mission.sqm. If they aren't in the correct order, rename them in the editor to have the correct order, rather than trying to edit mission.sqm.

[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline CrashDome

  • Members
  • *
Re: Syntax Question - Conditionals, Condition of Presence
« Reply #2 on: 05 Jul 2009, 01:39:50 »
As Spooner has said, you are expecting it to first check obj1 - then move to obj2 - then check obj3 if the first two aren't satisfied. That is a huge assumption.

What if it checks obj2 first and then obj1??

Your best bet is the place them all at 100% and make the conditional dependant on a random number, e.g.:

Obj1 - 100% probability - Condition: appear = 0
Obj2 - 100% probability - Condition: appear = 1
Obj3 - 100% probability - Condition: appear = 2

in an init line for an object (maybe obj1) or  trigger init line or init.sqf
Code: [Select]
appear = random 3;   //creates a random number from 0.0 to 2.999999
appear = appear - (appear mod 1);   //Drops the decimal values to give you 0,1, or 2,

I didn't use any command shortcuts just so you'd get an idea of what exactly is going on
« Last Edit: 05 Jul 2009, 01:43:03 by CrashDome »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Syntax Question - Conditionals, Condition of Presence
« Reply #3 on: 05 Jul 2009, 04:47:01 »
Floor is the best way to drop decimals. Your method is less clear, but was presumably necessary before the floor command was implemented.
Code: [Select]
appear = random 3;   //creates a random number from 0.0 to 2.999999
appear = floor appear;   //Drops the decimal values to give you 0,1, or 2,

Not convinced your suggestion will work, Crashdome, since I suspect that the way you are setting the variable is probably going to end up with it being set AFTER the 3 objects are checked for placing (and, appear being nil at this point, none will appear).

However, assuming that the methods we suggested didn't work, just cut the Gordian knot (sorry, I generally find scripting things avoids having to learn non-intuitive ways to use the editor). This also makes it very much easier to update, if you want to have a different number of objects. All objects should be set to appear normally in the editor:
Code: (keepOne.sqf) [Select]
// Call from init.sqf:
// _objects = [obj1, obj2, obj3];
// [_objects] execVM "keepOne.sqf";

if (not isServer) exitWith {};

private ["_objects", "_keep"];

_objects = _this select 0;
_keep = _objects select (floor random count _objects); // Choose one to keep.
_objects = _objects - [_keep]; // Remove it from the ones available.
{ deleteVehicle _x } forEach _objects; // Delete all the rest.

nil;
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline CrashDome

  • Members
  • *
Re: Syntax Question - Conditionals, Condition of Presence
« Reply #4 on: 05 Jul 2009, 18:59:34 »
Then much has changed. I wasn't even aware of a "Floor" command.

Even so, used within the init line of an object, the code should work. I've done it before - although I must admit I *may* have done the opposite and "deleted" units instead.

 I always thought condition of presence was checked after the init.sqf. In old OFP days, you could actually break the init.sqs script into two distinct parts - one that executed before (prior to briefing) and one that executed after the inits of objects simply by adding an "@" somewhere. I just assumed the sqf version simply ran before everything.

If those rules have changed, then I have to go back to scripting school.

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: Syntax Question - Conditionals, Condition of Presence
« Reply #5 on: 05 Jul 2009, 19:11:29 »
Offtopic:

Good to see you around CrashDome .  :)
Please check your PM here on the site.
Your mail addy no longer works too.

Offline CrashDome

  • Members
  • *
Re: Syntax Question - Conditionals, Condition of Presence
« Reply #6 on: 05 Jul 2009, 19:17:00 »
I will update my profile. It's been a long time :D


Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Syntax Question - Conditionals, Condition of Presence
« Reply #7 on: 05 Jul 2009, 22:17:07 »
init.sqf/init.sqs is always run after all objects have been created and init events run, unless you JIP in, in which case you need to wait until the player object is created before assuming all the objects have been created.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)