Jump to content
Sign in to follow this  
Ranwer135

Comparing 2 Strings in an 'If' statement using '==' - Need Help

Recommended Posts

So I am creating a function where you can easily fire off specific actions, e.g.:

[["DSS_Canteen_Filled_F", "Magazine"], ["DSS_Canteen_Empty_F", "Magazine"], "Eat"] call DSS_fnc_actionBrain;

//Eat is the focus of this issue.

Now when it passes the data across onto DSS_fnc_actionBrain, here is what happens in the .rpt:

19:31:17 Error in expression < then {_type = dss_fnc_eat};if ((_type == "Eat_Dry")) then {_type = dss_fnc_eat>
19:31:17   Error position: <== "Eat_Dry")) then {_type = dss_fnc_eat>
19:31:17 Error ==: Type code, expected Number,String,Not a Number,Object,Side,Group,Text,Config entry,Display (dialog),Control,Network Object,Team member,Task,Location

DSS_fnc_actionBrain:

dss_fnc_actionBrain = {

	_arrayRemove = (_this select 0); //Retrieves 1st Array
	_arrayAdd = (_this select 1); //Retrieves 2nd Array
	_type = (_this select 2); //Retrieves e.g. "Eat"

	//Type - Function
	if ((_type == "Drink")) then {_type = dss_fnc_drink};
	if ((_type == "Drink_Soda")) then {_type = dss_fnc_soda};
	if ((_type == "Eat")) then {_type = dss_fnc_eat};
	if ((_type == "Eat_Dry")) then {_type = dss_fnc_eatdry};

	[_arrayRemove, _arrayAdd] spawn _type; //Saves 1st and 2nd array and initializes _type.
};

What is going wrong here, am I missing some kind of special syntax, or doesn't it work with strings anymore?!? :blink:

 

 

 

Thanks,

 

 

 

Rawner135

Share this post


Link to post
Share on other sites

_type == "Eat_Dry" is comparing a function (dss_fnc_eat) to string ("Eat_Dry"), because you redefine the _type in the line above. That's why the error is "Type code, expected Number,String..."

 

Change either _type to something else, like _type2

 

Or you could change the multiple IFs to switch-do-case structure.

  • Like 1

Share this post


Link to post
Share on other sites

_type == "Eat_Dry" is comparing a function (dss_fnc_eat) to string ("Eat_Dry"), because you redefine the _type in the line above. That's why the error is "Type code, expected Number,String..."

 

Change either _type to something else, like _type2

 

Or you could change the multiple IFs to switch-do-case structure.

 

 

Thanks for the info, never thought about a switch control structure. Again, many thanks!  :D

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  

×