Jump to content
Sign in to follow this  
barmyarmy

Case Sensetive weapon names...

Recommended Posts

Weapon names in ARMA and probably OFP are case sensetive, when detecting weapons.

The following will always work..

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

player addWeapon "STINGER";

player selectWeapon "STINGER";

The following will NOT yeild the expected result...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if ( "STINGER" in weapons player) then {

hint "has a Stinger";

} else {

hint "has no stinger";

}

... but this will...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if ( "Stinger" in weapons player) then {

hint "has a Stinger";

} else {

hint "has no stinger";

}

A further warning using sidechat to list weapons will result in the weapon list being force to upper case, hints are left in the orginal case...

Share this post


Link to post
Share on other sites

This is due to the 'in' command which is case sensetive for strings. The boolean operators == and != are not case sensitive so

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if ( "StInGeR" == (weapons player) select 0) then {

hint "has a Stinger";

} else {

hint "has no stinger";

} should work.

Share this post


Link to post
Share on other sites
This is due to the 'in' command which is case sensetive for strings. The boolean operators == and != are not case sensitive so

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if ( "StInGeR" == (weapons player) select 0) then {

 hint "has a Stinger";

} else {

hint "has no stinger";

}

should work.

Yes that is true but your provided 'alternative' only checks the first item in the weapons array, to check them all using those operators you can try:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if({_X == "stinger"} count weapons player > 0)then{hint "has a Stinger";}else{hint "has no stinger";};

This is an identical alternative to using the in command, the only difference is it's not case-sensitive. However it's usually just easier to use the in command and get the cases right. wink_o.gif

Share this post


Link to post
Share on other sites

this was supposed to be a code example and no alternative. But you are right. Next time I will post the alternative instead of a similar example. That is just confusing for others tounge2.gif

Share this post


Link to post
Share on other sites

I also learned in OFP that if you for instance, call for a script in a trigger "[] exec "XXX.sqs"" and you name the script "xxx.sqs" it intermitantly caused MP issue with random people.

The same thing if you named a unit XXX and called the unit xxx in a script.

Share this post


Link to post
Share on other sites

Ok, so the "in" function is case sensitive...

I didn't realise that == was case-insensitive, but I suppose if it wasn't I'd have noticed before now and bitched about that too... *;/

Thanks for the code snippet Kyle, that does get round the problem nicely. Any idea what sort of performance hit you get using the hand-rolled function as oppose to the inbuilt "in" function ?

BA

Share this post


Link to post
Share on other sites
Thanks for the code snippet Kyle, that does get round the problem nicely. Any idea what sort of performance hit you get using the hand-rolled function as oppose to the inbuilt "in" function ?

BA

In this case, none.

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  

×