Jump to content
Sign in to follow this  
sickboy

How to get the position of a value in an array?

Recommended Posts

I am creating a script for custom faces for the llauma heads, that puts on specific faces depending on the name of the unit...

I am using these codebits in a script in the init eventhandlers of my units:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_u=_this select 0

_playn=name _u

_face=format["SIX_%1",_playn]

_u setFace _face

to select the right face from the faces pbo I created.

The problem now arises .. that when a player has a space in his name.. it will not work, since the class definitions of the faces do not allow spaces, of coarse.

I was breaking my head about a solution and came up with either removing the space from the name with some kind of string manipulation, of which I don't think is possible in OFP....(plz correct me if im wrong!!wink_o.gif

Or, create 2 arrays, the first with the playernames with a space, the second with the playernames (or other facedesignation) without a space.

Then lookup on which position the playername is in array1, and then select the right face from array2.

Now the question is...how do I lookup the position of the playername in array1, so I can use it to get the corresponding face from array2?

The hard way would be to count the faces and do a 1on1 check on every face and then use this codebit to determine the position:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while "_i >0" do {_ppos=(_i - 1); if ((SIX_FACES select _ppos) == _playn) then { _i=0 }; _i=(_i - 1) }

_playns=(SIX_FACESS select _ppos)

_face=format["SIX_%1_%2",_playns,_typ]

Any help, or alternatives welcome & appreciated! smile_o.gif

The above code is a working codebit from my code, but it's a bit much calculation in comparison to a possible simple command to obtain the position of a value within an array smile_o.gif

Share this post


Link to post
Share on other sites

Hi,

You can add the real names to a stringtable.csv file in your addon, for all the names you want to check.

Then use the localize command to retrieve the face name assigned to the real name:

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

It works with spaces, but I'm not sure what other characters it supports.

Share this post


Link to post
Share on other sites
Hi,

You can add the real names to a stringtable.csv file in your addon, for all the names you want to check.

Then use the localize command to retrieve the face name assigned to the real name:

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

It works with spaces, but I not sure what other characters it supports.

Holy crap, great idea.. gonna fiddle around with it wink_o.gif

Share this post


Link to post
Share on other sites

Ok the solution with localize is perfect, works as a charm smile_o.gif Thanks !

Moving to ME & S.

My bad confused_o.gif Didn't find such category in the flashpoint forums, I should've looked better..

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  

×