Jump to content
Sign in to follow this  
malkekoen

Scripting with false as condition and or

Recommended Posts

<disclaimer>I am a noob with scripting</disclaimer>

So I have a HC mission where the player is leading a force against a city. 3 different victory conditions are possible, one for few casualties, one for medium and one for heavy.

Ok, so I have a trigger that checks eg. if a tank is alive, and returns tankdead=true if it dies.

Now I want a the end triggers to activate depending on the casualties taken.

So I have eg:

wincon and tank1dead and tank2dead

wincon and (tank1dead or tank2dead)

wincon

But I cannot get the middle one to work. I tried without () as well, and begin to think I somehow misunderstands how it works. Is it only a number, and then how can it be setup?

I would also like to know how you can use false as a condition, like eg:

not or ! tank1dead (which would equal tank1dead=false).

Share this post


Link to post
Share on other sites

Conditions are just translations to either true or false.

!alive unit1 -- unit1 is not alive. - false

alive unit1 -- unit1 is alive. - true

!wincon -- is wincon false.

wincon -- is wincon true.

wincon and (tank1dead or tank2dead)

This should work as is, have you defined wincon,tank1dead and tank2dead as either true or false?

If you havent you could just check if its defined with isNil check:

wincon AND ( (!isNil "tank1dead" AND tank1dead) OR (!isNil "tank2dead" AND tank2dead) )

Personally i would not define the tank1dead before they were dead so in the trigger checking if they are not alive, id create the variable and then the condition would look like this:

wincon AND (!isNil "tank1dead" OR !isNil "tank2dead")

You can also instead of assigning a variable to the death of the tank, simply use

wincon AND (!alive tank1 OR !alive tank2)

Share this post


Link to post
Share on other sites

Thank you for the reply, Demonized.

The reason I set up the triggers as I did is in order to add more robustness to the mission.

So I use the "tank1dead=true" instead of just "!alive tank". My real triggers are a bit more complicated than I stated above, it was just for ease of reference.

In my scenario I have 7 friendly units that I "watch".

So the first is like:

Condition:

damage M1A2A >= 0.5 or ({alive _x} count units M1A2Agroup <3

On Act:

 [West,"HQ"] sidechat "M1A2/A is heavily damaged!"; M1A2Acon=true; playSound "radiobeep1";

And I have triggers checking for overall loss of infantry:

Condition:

({alive _x} count (units INFAgroup + units INFBgroup + units RECONAgroup + units COMAgroup)) < 20

On Act:

[West,"HQ"] sidechat "We have lost a lot of men"; InfantryLosscon=true; I1=false; playSound "radiobeep1";

Ok. Imagine now that I have 5 of these kind of triggers examining casualties.

Now the ending is based on the number of loses, so I have triggers set up with:

End trigger, least casualties:

Condition:

wincon

End trigger, medium casualties:

Condition:

wincon and (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon)

End trigger, severe casualties:

wincon and M1A2Acon and M1A2Acon and LAV25Acon and InfantryLosscon

So the problem is the middle one. I think it only works with 2 conditions, like (M1A2Acon or M1A2Bcon), but I am checking for several conditions to be true. Is there any way of doing this in the editor, or would I need a special script?

Maybe instead add a counter, and make it add a value each time a condition is fulfilled?

Share this post


Link to post
Share on other sites

i think maybe you just have this typo

M1A2Acon and M1A2Acon

thats in last trigger, severe casualties, and in the middle condition you use A and B on the M1A2 variables.

check your M1A2Bcon.

hopefully that was it......

Share this post


Link to post
Share on other sites

No it wasn't that. Just checked my orginal triggers and I simply just made the typo when transferring it here to the forums, sorry :o

But the trouble is this:

wincon and (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon)

and this:

wincon

It always seem to activate the second trigger and ignoring the first, even if one or more of the conditions are true. So I think maybe there's something wrong with the logic, that it simply ignores the OR statements as they are somehow invalid...

Share this post


Link to post
Share on other sites
No it wasn't that. Just checked my orginal triggers and I simply just made the typo when transferring it here to the forums, sorry :o

But the trouble is this:

wincon and (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon)

and this:

wincon

It always seem to activate the second trigger and ignoring the first, even if one or more of the conditions are true. So I think maybe there's something wrong with the logic, that it simply ignores the OR statements as they are somehow invalid...

Yes the first logic is not right, the (or) command can only evaluate two values.

Your first code should look like this:

wincon and ((M1A2Acon or M1A2Bcon) or (LAV25Acon or infantrylosscon))

You have to break it down with () into sections of two that can be evaluated.

Share this post


Link to post
Share on other sites
Yes the first logic is not right, the (or) command can only evaluate two values.

Your first code should look like this:

wincon and ((M1A2Acon or M1A2Bcon) or (LAV25Acon or infantrylosscon))

You have to break it down with () into sections of two that can be evaluated.

not true, this is where paranteces comes in.

is this value == (the total value of this)

simple test just to prove its not a brainfart.

placed player in editor, with this in player init.

test1 = true; test2 = true; test3 = true; test4 = false; test5 = false;

placed hint trigger with this in condition:

test1 AND (test2 OR test3 OR test4 OR test5)

start mission trigger activates showing hint.

double checking: making all variables in player init false, and use a radio trigger to set some of them to true manually in mission after mission start and its working...

so to sum up:

you can have as many OR´s inside a paranteces as variable, it will check if only one or more is true, then be true for the whole paranteces.....

this however will error out, so you need the paranteces:

test1 AND test2 OR test3

Share this post


Link to post
Share on other sites

Have you initialized all the variables in init.sqf or somewhere? Each of those values needs to defined for the condition work.

Share this post


Link to post
Share on other sites

Thank you all of you! I am away from home atm due to my job, but I can't wait to get home and try it out. I've been trying to figure this out for a week :confused:

Share this post


Link to post
Share on other sites

@Demonized

Nice test, due to the wording I was under the impression that you could only evaluate two values.

Share this post


Link to post
Share on other sites

Demonized:

With the following values as fixed:

test1 = true; test2 = true; test3 = true; test4 = false; test5 = false;

and this in the trigger:

test1 AND (test2 OR test3 OR test4 OR test5)

Is it not the same as my:

wincon and (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon)

which consistenly chooses another trigger that is called:

wincon

even though all or some of the other parameters have been achieved?

Would your trigger activate as well if you had one other that said:

test1

Hope you get my point.

Share this post


Link to post
Share on other sites
which consistenly chooses another trigger that is called:

So, you have two triggers?

One with:

wincon and (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon)

and another with:

wincon

?

Share this post


Link to post
Share on other sites

Yes I have set up 3 triggers, each determing the outcome of the mission (level of succes). This is from my 3rd post:

End trigger, least casualties:

Condition:

wincon

End trigger, medium casualties:

Condition:

wincon and (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon)

End trigger, severe casualties:

wincon and M1A2Acon and M1A2Bcon and LAV25Acon and InfantryLosscon

So the problem is the middle one. I think it only works with 2 conditions, like (M1A2Acon or M1A2Bcon), but I am checking for several conditions to be true. Is there any way of doing this in the editor, or would I need a special script?

Maybe instead add a counter, and make it add a value each time a condition is fulfilled?

I gave it some thought. Maybe the thing is that you need to set up false as a condition specifically:

End trigger, least casualties:

Condition:

wincon and !M1A2Acon and !M1A2Acon and !LAV25Acon and 
!InfantryLosscon

End trigger, medium casualties:

Condition:

wincon and (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon)

End trigger, severe casualties:

wincon and M1A2Acon and M1A2Bcon and LAV25Acon and InfantryLosscon

Is it possible to define a condition as false like this !condition? Is that proper grammar?

Share this post


Link to post
Share on other sites

wincon

is condition true, if yes activate.

!wincon

is condition false, if yes activate.

Maybe it would be easier to script the ending:

{_x = false} foreach [wincon, M1A2Acon, M1A2Bcon, LAV25Acon, infantrylosscon];  // set all variables to false at mission start.
_end = "END1";  // default end if only wincon is true.
waitUntil {sleep 1; wincon};  // check if wincon is set to true every 1 seconds, if so proceed.
// now we already know that wincon is true so we dont need to include it in our checks.

//  medium casualties:
if (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon) then {
_end = "END2";
};
//  severe casualties:
if (M1A2Acon and M1A2Bcon and LAV25Acon and InfantryLosscon) then {
_end = "LOSER";
};
endMission _end;  // end the mission.

Share this post


Link to post
Share on other sites

Thanks for the script Demonized. I have just tried it, and I need to modify it a little bit to suit the needs of the mission.

Instead of ending the mission at the preset conditions, I will rather make a condition true, as in this:

{_x = false} foreach [wincon, wincon1, wincon2, wincon3, M1A2Acon, M1A2Bcon, LAV25Acon, infantrylosscon];  // set all variables to false at mission start.
_end = wincon1=true;  // default end if only wincon is true.
waitUntil {sleep 1; wincon};  // check if wincon is set to true every 1 seconds, if so proceed.
// now we already know that wincon is true so we dont need to include it in our checks.

//  medium casualties:
if (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon) then {
_end = wincon2=true;
};
//  severe casualties:
if (M1A2Acon and M1A2Bcon and LAV25Acon and InfantryLosscon) then {
_end = wincon3=true;
};
endMission _end;  // end the mission.

Unfortunatly this doesn't seem to work. Do you know how to make the conditions right?

Another thing, I tried running it through the init file, but it never started. If I run at eg. players initialization field it works fine. This is what I wrote in the init file:

[] execVM "scripts\end.sqf";

Thought that ought to do it...

Edited by malkekoen
Spelling

Share this post


Link to post
Share on other sites
Instead of ending the mission at the preset conditions, I will rather make a condition true, as in this:

{_x = false} foreach [wincon, wincon1, wincon2, wincon3, M1A2Acon, M1A2Bcon, LAV25Acon, infantrylosscon];  // set all variables to false at mission start.
_end = wincon1=true;  // default end if only wincon is true.
waitUntil {sleep 1; wincon};  // check if wincon is set to true every 1 seconds, if so proceed.
// now we already know that wincon is true so we dont need to include it in our checks.

//  medium casualties:
if (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon) then {
_end = wincon2=true;
};
//  severe casualties:
if (M1A2Acon and M1A2Bcon and LAV25Acon and InfantryLosscon) then {
_end = wincon3=true;
};
endMission _end;  // end the mission.

Unfortunatly this doesn't seem to work. Do you know how to make the conditions right?

dont think you can use special characters in a variable, wincon=true, use underscores or something nifty in naming, i seperate words with capital letters.

myVariable or my_variable.

and for the script, you need to work out the flow of your script, unless i totally misunderstand you:

i used the endMission command in my previous post, wich is the same result as end with a trigger, click the command link and you see the failmission command and more info for saves etc..

if i understand correctly:

{_x = false} foreach [wincon, wincon1, wincon2, wincon3, M1A2Acon, M1A2Bcon, LAV25Acon, infantrylosscon];  // set all variables to false at mission start.
waitUntil {sleep 1; wincon};  // check if wincon is set to true every 1 seconds, if so proceed.
// now we already know that wincon is true so we dont need to include it in our checks.

//  severe casualties:
if (M1A2Acon and M1A2Bcon and LAV25Acon and InfantryLosscon) then {		// if all of these are true:
wincon3 = true;									// do this.
} else {											// else :p
//  medium casualties:								// do this.
if (M1A2Acon or M1A2Bcon or LAV25Acon or infantrylosscon) then {	// if any of these is true:
	wincon2 = true;								// do this
} else {										// else :p
	wincon1 = true;								// do this.... here we choose the WIN since none of the above is true.
};
};
// here script auto exit on its own.

Another thing, I tried running it through the init file, but it never started. If I run at eg. players initialization field it works fine. This is what I wrote in the init file:

[] execVM "scripts\end.sqf";

Thought that ought to do it...

should be fine inside init.sqf, though in init linies of units/objects or in triggers you need a dummy handle:

[b][size=4]_null = [/size][/b][] execVM "scripts\end.sqf";

Edited by Demonized

Share this post


Link to post
Share on other sites

That works like a charm!

Thank you so much Demonized, that has really been a head ache! You help is really appreciated!

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  

×