Jump to content
Sign in to follow this  
merlin

Nesting IF THEN statements

Recommended Posts

SOLVED Thanks Iceman!!

This thread was of some help but i am still having trouble with my application.

This script is used to identify vehicles and positions of interest to complete mission objectives. I want the script to first identify if the cursortarget is a vehicle, then to further find out what kind of vehicle the player is looking at and assign points or complete mission objectives accordingly. If the target is not a vehicle I want it to decompose the coordinates from screentoWorld, and then check if it is important.

My problem is in nesting this if then statement to detect specific vehicles the player is pointing at. Without the red bit it works fine, identifying vehicle type when the player points at a vehicle, and the terrain coords otherwise. When i have the red bit I do not receive any hints.

 private ["_ctarg","_cvtarg","_campos"]; 

_ctarg = cursortarget;				//CURSOR ENTITY
_campos = screenToWorld [0.5,0.5];		//SCREEN POSIT
_cvtarg = typeof cursortarget;			//TYPE OF VEHICLE
private ["_ctarg","_cvtarg","_campos"]; 


if (_ctarg isKindOf "landvehicle") then
{
hint str typeof cursortarget
[color="#FF0000"]	if (_cvtarg == "O_MBT_02_arty_F") exitWith {arty1 setdamage 1};[/color]
 } else {

	hint format["Posit %1",_campos];

};

I haven't attempted the screentoworld check yet but i imagine it will look something like this.

This is a bit off topic but i'm curious if this kind of condition syntax is acceptable (in green).

_camposx = _campos select 0;
_camposy = _campos select 1;
//OBJECTIVE IS 9748 15874, check of screentoworld is within 20m
if (9738 < _camposx < 9758) && [color="#008000"](15864 < _camposy < 15884)[/color] then 
{
    hint "objective complete"
}

Thanks!

Edited by Merlin

Share this post


Link to post
Share on other sites
_vehTypeArray = ["Armored", "Air", "Car"];

if ( !isNull cursorTarget && {getText (configFile >> "cfgVehicles" >> typeOf cursorTarget >> "vehicleClass") in _vehTypeArray} ) then {
 hint format ["The cursor target exists and you know enough about it and the cursor target is a vehicle and to be exact it's an %1 !!!", typeOf cursorTarget];

};  

Edited by Iceman77
Fixed typo

Share this post


Link to post
Share on other sites
_vehTypeArray = ["Armored", "Air", "Car"];

if ( !isNull cursorTarget && {getText (configFile >> "cfgVehicles" >> typeOf cursorTarget >> "vehicleClass") in _vehTypeArray} ) then {
 hint format ["You know enough about the cursor target and the cursor target is a vehicle and to be exact it's an %1 !!!", typeOf cursorTarget];

};  

I really appreciate the fast response, if I understand correctly I would just replace the red "vehicleClass"with the classname of say a howitzer that i want the player to spot and it should work?

Is this correct?

 
[color="#696969"]private ["_ctarg","_cvtarg","_campos"]; 

_ctarg = cursortarget;				//CURSOR ENTITY
_campos = screenToWorld [0.5,0.5];		//SCREEN POSIT
_cvtarg = typeof cursortarget;			//TYPE OF VEHICLE
private ["_ctarg","_cvtarg","_campos"]; 

[/color]
if (_ctarg isKindOf "landvehicle") then
{

_vehTypeArray = ["Armored", "Air", "Car"];

if ( !isNull cursorTarget && {getText (configFile >> "cfgVehicles" >> typeOf cursorTarget >>[color="#FF0000"] "O_MBT_02_arty_F"[/color]) in _vehTypeArray} ) then {
    hint format ["I spot the %1 and now i will destroy the mission objective!!!", typeOf cursorTarget];
   arty1 setdamage 1;
};  

// [color="#008000"]i'd like to have 5 or 6 of these for different types of vehicles to spot, each one completing a mission objective.[/color]

if ( !isNull cursorTarget && {getText (configFile >> "cfgVehicles" >> typeOf cursorTarget >>[color="#FF0000"] "Some other vehicle class..."[/color]) in _vehTypeArray} ) then {
    hint format ["I spot the %1 and now i will destroy the mission objective!!!", typeOf cursorTarget];
   othervehicle1 setdamage 1;
};  
[color="#696969"]
 } else {

	hint format["Posit %1",_campos];

};[/color]

Edited by Merlin

Share this post


Link to post
Share on other sites

Looks okay to me from a quick glance. One thing I noticed is that you're checking for land vehicles, so you don't need the "air" string in the _vehTypeArray as that will never be a possibility.

---------- Post added at 15:59 ---------- Previous post was at 15:55 ----------

ewww. wait. At the end you've the classname. ie; "O_MBT_02_arty_F". typeOf cursortarget IS the classname (string). The very last string in the cfg line is literally "vehicleClass". That retrieves the vehicle class cfg entry (text string). IE; "Armored", "Air", "Car", "Men"

---------- Post added at 16:16 ---------- Previous post was at 15:59 ----------

After looking through your script(s) more finely, I'm not 100% on what you're up to, but you can take a look at this post. It's a small script to call in an airstrike (creates the projectile aswell) with a laser designator.

Share this post


Link to post
Share on other sites

I keep running across threads that talk about Switches/Switching; yet when I look it up on the BIKI, it says it's depreciated. Do they actually still work in ARMA 3? Because that seemed like a cleaner way of nesting IF ELSE type statements.

Share this post


Link to post
Share on other sites

Maybe this better defines my problem.

This does what i'd like, when i point at a howitzer and run the script it blows up, when i'm not pointing at ti and i run the script i get the coords.

private ["_ctarg","_cvtarg","_campos"]; 
_ctarg = cursortarget;				//CURSOR ENTITY
_campos = screenToWorld [0.5,0.5];		//SCREEN POSIT
_cvtarg = typeof cursortarget;			//TYPE OF VEHICLE


if (_cvtarg == "O_MBT_02_arty_F") then {arty1 setdamage 1}
  else {
	hint format["Posit %1",_campos];
};

I'd like the script to check if i'm looking at a vehicle, then proceed to interrogate it to find out what kind, and update objectives accordingly, otherwise it would check the coords.

I would think nesting the specific vehicle IF THEN check (in this case just a howitzer) like this would work but i don't get any hint when i run the script.

if (_ctarg isKindOf "landvehicle") then    //check if looking at a vehicle
{
hint str typeof cursortarget     //just for debug

	if (_cvtarg == "O_MBT_02_arty_F") then {arty1 setdamage 1};    //if the vehicle is a howitzer blow up the objective

	if (_cvtarg == "some MRAP classname") then {mrap1 setdamage 1};    //if the vehicle is an MRAP blow it up

 } else {
	hint format["Posit %1",_campos];
};

For this i believe i would use exitwith, but upon testing i still get no hint.

Edited by Merlin

Share this post


Link to post
Share on other sites
I'd like the script to do check if i'm looking a vehicle, then proceed to interrogate it to find out what kind ... upon testing i still get no hint.

The code in post #2 does that (aswell as your landVehicle check) and your missing a ; at the end of your hint.

Edited by Iceman77

Share this post


Link to post
Share on other sites

hint format doesn't seem to work :(

I've tried each of the lines individually and they all do what i want, that is to say i can identify what type of vehicle the player is looking at. my problem is in combing them together in a tree, (i believe nesting is the term for this). Once i put an IF THEN statement inside another the whole script seems to fail.

I made a flowchart to illustrate what i'm trying to do.

whenever i try to implement the checks in the red circle the script does not supply me with any hints.

asmn0Xi.png

Edit: lol, sorry to have put you guys through this. it works great now, thanks for your patience Iceman!

Edited by Merlin

Share this post


Link to post
Share on other sites

You're missing a ; at the end of your hint.

---------- Post added at 16:57 ---------- Previous post was at 16:48 ----------

Additionally, as Pillow mentioned, you can use a switch statement (if you prefer) so it will not continue to evaluate any proceeding conditions after a condition has returned true.

So like

switch (typeOf cursorTarget) do {
case "O_MBT_02_arty_F":{cursorTarget setDamage 1;};
case "some_MRAP_Class":{cursorTarget setDamage 1;};
case "some_AIR_Class":{cursorTarget setDamage 1;};
case "some_MAN_Class":{cursorTarget setDamage 1;};
};

---------- Post added at 17:01 ---------- Previous post was at 16:57 ----------

Edit: lol, sorry to have put you guys through this. it works great now, thanks for your patience Iceman!

I'm in a cabin, in the woods, with alot of time. So it's not a bother.

---------- Post added at 17:13 ---------- Previous post was at 17:01 ----------

Yet when I look it up on the BIKI, it says it's depreciated.

Post a link to this Biki page please. I'm curious. In my way of thinking, If statements themselves are faster, but how could switch possibly be depreciated when it's sole purpose is to evaluate, find a true condition and exit (without continuing to evaluate un-needed conditions)? Surely it can't be that slow, to the point where it's purpose is null and void.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Well i've run into another hurdle, this one more straightforward.

I'd like to identify specific named entities for some vehicles so rather than every vehicle of a type registering i only want one, in this case the tank named "kuma1".

My assumption is that cursortarget passes the entity's name, either i've made a mistake or this is not the case.

Is there a command that would function like:

(nameof cursortarget == kuma1) (i've looked and i've found nothing of the sort)

_ctarg = cursortarget;				//CURSOR ENTITY
_campos = screenToWorld [0.5,0.5];		//SCREEN POSIT
_cvtarg = typeof cursortarget;			//TYPE OF VEHICLE

if (_ctarg isKindOf "landvehicle") then
{
hint str typeof cursortarget;
	if (_cvtarg == "O_MBT_02_arty_F") exitWith {arty1 setdamage 1};
	if (_cvtarg == "O_MRAP_02_F") exitWith {mrap1 setdamage 1};
if (_ctarg == "kuma1") exitWith {kuma1 setdamage 1};
....
};

Edited by Merlin
php is nice

Share this post


Link to post
Share on other sites
(nameof cursortarget == kuma1)

if (cursorTarget == kuma1) exitWith {
    kuma1 setDamage 1;
};

Edited by Iceman77
Changed it to an exitWith

Share this post


Link to post
Share on other sites
I keep running across threads that talk about Switches/Switching; yet when I look it up on the BIKI, it says it's depreciated. Do they actually still work in ARMA 3? Because that seemed like a cleaner way of nesting IF ELSE type statements.

Uh where'd you find that?

They work just fine and I use them all the time.

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  

×