Jump to content
Sign in to follow this  
Linker Split

Comparing two strings

Recommended Posts

Ok, let me explain you what i want to achieve:

I want that when my character is near for example a bush, then the engine recognizes it is the bush lks_bush_leaf3_big.p3d and execut the second part of the script.

Now I'm stuck at this simple string identity, cause I want to compare the string lks_bush_leaf3_big.p3d and the one the engine recognizes through the line _r_obj = str "_obj"

if I put the famous trial line hint format ["%1",_r_obj], it works, the hint appears: lks_bush_leaf3_big.p3d

but when coming to the identity, it doesn't work. why?huh.gif

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

;my unit

_Character = _this select 0

#START

;find the nearest object in order (passed array which elements are: 0 = player, 1 = nearest object)

_near_obj = nearestObjects [_Character,[],3]

;select the array select 1, so the real object

_obj = _near_obj select 1

:convert the object into a string

_r_obj = str "_obj"

;identity which doesn't work

? _r_obj == "LKS_bush_leaf3_big.p3d" : _Character setDammage 1

~1

goto "START"

Share this post


Link to post
Share on other sites

you say

_r_obj = str "_obj"

look closely and you wwill realise that you are saying arma to convert into a string something that is insde "" that means to convert the string _obj into a string that's why it doesn't work. try it without the ""

_r_obj = str _obj

Share this post


Link to post
Share on other sites

yeah, sorry, I'm tired, i forgot to tell you i tried also without quotes.. .anyway, even without quotes, it gives me this hint:

immagineva5.jpg

but still it is not working.

This whole thing is bugging me crazy_o.gif

Share this post


Link to post
Share on other sites

look at the picture  whistle.gif

There is a number in front of the name which you have to cut off.  smile_o.gif

Share this post


Link to post
Share on other sites
look at the picture whistle.gif

There is a number in front of the name which you have to cut off. smile_o.gif

so you think that the engine is passing the whole string with the number and the : instead of the only name?

Share this post


Link to post
Share on other sites

sure (you get a string like the one in the picture)

normally I would use "typeof" but because the bushes and trees (not editor placed) are classless that's not possible.

Share this post


Link to post
Share on other sites
sure (you get a string like the one in the picture)

normally I would use "typeof" but because the bushes and trees (not editor placed) are classless that's not possible.

so hmm.... how to cut the numbers down?

do you have any idea?

Share this post


Link to post
Share on other sites

different ideas:

1) use "toArray", find the space (find 32) and rebuild the string by using a loop through the array from (find 32) to (count array)-1 and then toString or

2) toString((toArray (str _obj)) - toArray "0123456789: ")  (or better the unicodes directly) but here all numbers and : and spaces in the name are gone

(perhaps I say nonsense and there is an easier way (which I don't know) to do this biggrin_o.gif)

Share this post


Link to post
Share on other sites
different ideas:

1) use "toArray", find the space (find 32) and rebuild the string by using a loop through the array from (find 32) to (count array)-1 and then toString or

2) toString((toArray (str _obj)) - toArray "0123456789: ") (or better the unicodes directly) but here all numbers and : and spaces in the name are gone

(perhaps I say nonsense and there is an easier way (which I don't know) to do this biggrin_o.gif)

Ok m8 downloaded, tomorrow I'll try them and see what can be done

smile_o.gif thank you for your attention

Linker Split

Share this post


Link to post
Share on other sites

Comparing strings is case sensitive. Set them all to upper case before you compare them.

--Ben

Share this post


Link to post
Share on other sites

"==" isnt case sensitive. checking with "in" is.

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

"blabla" in ["BlABLa","BLABLA"] //is false

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  

×