Jump to content
Sign in to follow this  
ArMoGaDoN

String Functions

Recommended Posts

Found Kronzky's 'fudge' library to make string functions available, and as the authors themselves note, they are very slow and CPU intensive, being based upon the brute-force way of doing things.  Amazing that it even works when I took a peek at it.

Have there been any noises made regarding possible inclusion of some basic string-handling and slicing commands in the next (please...) or future patch?  Seems stupid to be able to hack arrays as you wish, and netcode can't send arrays - but can now send strings.

BUT when you get a string to the other end, you cannot hack it apart again.  Hmm, methinks that if string slicing was available it'd be a simple matter to pack an array into a string, send the string, then unpack the string back to an array again at the other end.  IMO this facility is badly needed.

I thought it could already be done?huh.gif?

Share this post


Link to post
Share on other sites

Well it was a disappointment for me to notice that Armed Assault doesn't provide string manipulation functions for us as found in for example C/C++.

There must be some good reason for BIS to not include such functions. If it is purely a business decision then it is okay for me. If the reason is technical then I'd like to hear it from BIS. If the reason is performance problems then I say leave it to mission designers to decide if their mission is too heavy or not.

An ugly hack is really just that, an ugly hack which might or might not work in future versions.

Share this post


Link to post
Share on other sites

Put the array in a string, publicVariable that. On the other end call compile it to turn it back to an array.

I've never really understood what the string functions could be used for, yet it's the most voted for feature request. Could someone explain just how they could be used in a mission?

All I could think of is some kind of text command parser like the old (80's) Sierra adventure games. Which could be cool, but absolutely ridiculous.

Share this post


Link to post
Share on other sites
Put the array in a string, publicVariable that. On the other end call compile it to turn it back to an array.

I tried this method and encountered problems with objects and groups. See this issue in the BTS

Share this post


Link to post
Share on other sites

As fasad said, send arrays as strings.

Quote[/b] ]I've never really understood what the string functions could be used for, yet it's the most voted for feature request. Could someone explain just how they could be used in a mission?

I understand where your comming from, when there are more important issues to address in Arma. I guess it could help to make some code neater. I'm sure dialogs would benefit from it. But IMHO it's not essential, as there are plenty of ways to do the same thing. Unless someone can suggest something that could not be done without them?

Quote[/b] ]If you convert an object or group to a string variable and want to convert it back with call compile you get an error that a ']' is missing.

If you tried to represent all the properties on an object using a string, it would be massive. Think of some of it's config entries, all the mission.sqm entries and all the save game data plus some more. Packed into one single string, it will never work that way.

If you want to pass references for objects using strings, use variable names. Or add them to reference arrays and pass the index over the network. Much more efficent

Share this post


Link to post
Share on other sites
Put the array in a string, publicVariable that. On the other end call compile it to turn it back to an array.

I tried this method and encountered problems with objects and groups. See this issue in the BTS

To overcome that, you have to give each element of the array an public'ed name. I made a script to do that a while ago, IIRC. Contact me on ICQ if you're interested.

Share this post


Link to post
Share on other sites
Put the array in a string, publicVariable that. On the other end call compile it to turn it back to an array.

fasad

Please, how would this be done?

It would help me out a LOT if I knew how to do this.

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

_function = "a = a + 1"; _compiled = compile _function; call _compiled;

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

_myArray = {"element1","element2"};

myPublicArray = compile _myArray;

publicVariable "myPublicArray";

myClientArray = compile "myPublicArray";

or? confused_o.gif

Share this post


Link to post
Share on other sites

I'll give you an example. I can't explain the logic 'cause I'm tired, can just barely script myself, and created this by the seat of my pants smile_o.gif

This is for a MP artillery script. One client uses a dialog to create and then start a fire mission. When this happens, the client "throws" an array to the server, which executes the artillery events (firing the guns, creating shells etc). This was done to avoid any possible lag or desync. I don't really know if it was needed but it works none the less.

client "throw" code:

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

....

CEEB_artiGV = format["[""%1"",%2,%3,""%4"",%5,%6]",_groupName,_targetPos,_salvos,_shellType,_timing,_precisionMult];

publicVariable "CEEB_artiGV";

server "catch" code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call compile format ["%1 execVM ""CEEB_artilleryDialog\artilleryControl.sqf""",CEEB_artiGV];

Things to note:

* Strings need to have "quotation marks" added around them when put into an array.

* Group and unit references are passed using a string of the name or global variable name. I've got into the habit of doing this for most scripts, since I used GV names for markers, arrays etc, dynamically created from the string of the group variable name for an old OFP project. Strings of variable names can alway be converted into the variable they represent, but not the other way around (AFAIK).

Share this post


Link to post
Share on other sites

Regarding the practical applications of string functions - there are a few that are always at the top of my mind:

The main one is the recognition of unclassed objects.

Say, for example, you want to quickly find out whether a location is near a road. So you do a nearestObjects which returns an array that might contain some references to roads, but also to all kinds of other "decoration". Since most of them are not classes it's pretty much impossible to weed out the roads this way. (The same applies of course to any other unclassed map objects that you're trying to locate).

There are some other potential uses - (like determining whether a unit has been named or not, retrieving the ID# from an object, or not caring about whether a call parameter was entered upper or lower-case or mixed, etc., etc.) but, for me at least, finding map objects would definitely be at the top of the list.

Share this post


Link to post
Share on other sites

Ahhh, True! I now remember suggesting that someone use your functions to find road objects just a couple of weeks ago. A modelName command or extension of typeOf would also do the job there. As for the practicality of the current solution I guess it depends on how fast you need to do it.

Any other uses?

Share this post


Link to post
Share on other sites
Quote[/b] ]So you do a nearestObjects which returns an array that might contain some references to roads

According to the Wiki nearestObjects requires a class name(s)?

Quote[/b] ]Second element is the classname of the object or objects to be searched for, this can be a single classname or an array of classnames.

If I remember correctly from ofp, you had to use an object ID to get things like roads and bushes e.t.c But given you know the object ID's then you could just read the height above ground to identify if it was a roadway or not?

Don't get me wrong, I'm not saying string functions aren't usefull. For example, it would not give you the type of roadway, so you could use string functions to extract the name of the p3d.

It's more, how usefull compared to other missing functions in the game?

Share this post


Link to post
Share on other sites

thanks for all the answers guys,

@fasad - regarding your 'compile the string' thing,

I get what you have done, using the string as creating the parameters to a function call.  I can see that would work fine for simple stuff.  I wondered, after reading your reply, though, if there's a way to use compile itself without the function call to unpack a string back into an array...

I tried this from a radio trigger, sure enough the string gets built, and the call compile runs!

e.g.

a=[10,20,30,40,50];

s=str(a);

hint s;

;that results in "[10,20,30,40,50]" in a hint

~2

a2=call compile s;

b=a2 select 2;

s=s+str(b)

hint s

;that results in "[10,20,30,40,50]30" in a hint

~5

I searched for ages on the web, here on forums and in BIS documentation, and found no references to this quirky shortcut at all.  I sorta remember reading it a while ago - but when searching for a memory-jogger - no joy.  Thanks for the info.

@raedor - I asked here in desperation in the first place, as I am also resorting currently to many separate public variables being used to transmit the contents of several arrays nested in another.  This means each sub-array being transmitted separately too via those variables.  It's a very complex answer for what should be a simple job.  

I would be very interested in seeing your more generic solution to the problem (the code I have here is sorta dedicated to the type of data-structures I am playing with).  

Have requested you add me on ICQ.

But if there's a better way to use strings, that which fasad said about looks very promising as there's a fixed limit on sub-array size of 30 elements, which would translate well to a function call such as he dscribed.  Will try it.

edit: Well I am very happy to report that even multidimensional and ragged arrays work properly, when those contain just numbers. I have not yet tried it with string values in the array or anything else.  But with numbers it works fine.

e.g.

M=[10,12,12,0,[0,1,3],[12,10,8,7],[2,2,2],[12,12,9],[1,1,0],[0,0]];

that gets translated to a string and back just fine using the above method.

Thanks!

I still think that string functions should be provided by the engine. There's a lot of other things that could be encoded in strings that would be very useful now that strings can be publicVariable'd, besides those things that Kronsky said - which I agree with too.

Share this post


Link to post
Share on other sites
According to the Wiki nearestObjects requires a class name(s)?
Quote[/b] ]Second element is the classname of the object or objects to be searched for, this can be a single classname or an array of classnames.

It requires a class parameter. But that can be empty.

e.g.<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">nearestObjects [player,[], 10]

Share this post


Link to post
Share on other sites
Quote[/b] ]if there's a way to use compile itself without the function call

If you mean like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">MYARRAY=Call Compile "[10,12,12,0,[0,1,3],[12,10,8,7],[2,2,2],[12,12,9],[1,1,0],[0,0]]";

Quote[/b] ]It requires a class parameter. But that can be empty.

Ok, cheers. I'll go update the wiki.

Share this post


Link to post
Share on other sites

I am in a hurry so I will make this brief:

As much as string manipulation in code is pointless and sometimes more complex than a workaround, the ability to perform manipulation on strings in the UI is something I would consider a basic necessity.

I don't see many dialogs from OFP requiring it as much, but a good example is a filter. Perhaps I have a list of names of people online. Lets pretend it is a list of 100 people (since we are pretending - i will pretend this grand proclamation by BIS is also true). Lets say I want to sort this list Alphabetically or filter out only names containing wildcard chars. Since the UI does not include these options, it would be possible to do so via a script/function provided we could manipulate strings. Additionally, I could foresee many other applications where string manipulation would be really handy that cannot be done otherwise (mostly as parsers). So, I still consider it a viable option but I won't be waving a flag around because it isn't *that* important to me personally. It certainly doesn't impact gameplay - only engine limits.

Share this post


Link to post
Share on other sites

yay.gif

I got it working!

the server packs an array

publicVariable that

and teh client can unpack the publicVariable and display the array with "ablabla select 1;"

Thanks ya all

smile_o.gif

Share this post


Link to post
Share on other sites

Another usage for string functions would be to determine if a unit had a weapon in their hand or not.

With a "contains in string" function you could could check if values "rfl" (rifle) or "pst" (pistol) were contained in the string returned by animationSate.  If the "rfl" or "pst" subsgtring is in the string, then the unit has a weapon in his hand.

Useful when walking around town with your gun hidden/holstered, but want people to react to you when you whip it out (the gun that is).

Share this post


Link to post
Share on other sites

Or, to actually see a practical use for string manipulation that I've done, take a look at the code import feature on my particle parameter utility in my signature.

It lets you paste most any valid particle code into the fields, parses it, and updates the effect in real time.

There's a vast amount of things that can be done as far as accpeting user input from a dialog goes when you have string manipulation.

Frankly, I just consider it to be an oversite. If I had access to the source, I could probably add it in like 1/2 an hour tops.

Ohh, for anyone interested:

The original thread that lead up to the string library:

http://www.flashpoint1985.com/cgi-bin....=60261;

And the release thread:

http://www.flashpoint1985.com/cgi-bin....=60380;

Share this post


Link to post
Share on other sites

As johnnyboy says above, you need string manipulations to script anything that depends on animation names. My own binotarget uses the string functions to detect if a player is holding binoculars or not.

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  

×