Jump to content
Sign in to follow this  
m0nkey

How to concatenate a variable into a string when it must be within a string???

Recommended Posts

This one stumps me, completely.

I have a script that spawns a group. I put some data associated with the group into a multidimensional array. For example:

arValues set [count arValues, [_uniqueID,_message,_value]];

We could suppose it might look like this

      0         1                 2
0    5     "test5"     "5 blind mice"
1    10    "test10"   "10 pieces of 8"
2    15    "test15"   "15 bearded ladies"
3    20    "test20"   "20 bottles of bourbon"

Each time the script is called, it will create a new waypoint and add to the array 3 passed parameters: a unique ID like 22, a message like "Test22" and a value like "22 bottles of beer on the wall". So the end result is that a group is spawned, a waypoint created, the incoming parameters stored in an array.

I now want to, when waypoint condition is true, display those values or work with them in different ways. To build such a statement I am pretty sure you have to build a string value and use globals. An example might be

_objWP setWaypointStatements ["TRUE", "hint str ((arValues select 1) select 2);"];

which would display "10 pieces of 8".

What I am trying to figure out, is if its possible to build that "statement" by passing in the index of the array I just wrote those values to. For example, say I did this

_int = count arValues;  (say it was 4)
arValues set [_int,[25,"test25","25 bronze beauties"]];
_objWP setWaypointStatements ["TRUE","hint str ((arValues select " & _int & ") select 2);"]; (which references index 4, element 2 aka "25 bronze beauties")

I know the ampersand does not concatenate in this script language. Thats how you would do it though in many languages. Can this be done? How?

Thanks to anyone who might share. (i'll be gone till late sunday, so won't be able to reply for a bit fyi)

Oh, forgot to mention, I just picked spawning and waypoints to mess with because it seems a common task and there are plenty of other people work to look at. Somehow I got it in my mind to make the waypoint do something when the group reached it and it turned true. And for some reason I wanted to use an array with it as well. I am sure to learn a thing or two from it though ;)

One more question I just thought of. When it is stated that a waypoint is "done" when its condition is fulfilled (the group/unit reached it), then the statement fires. I take it that once a waypoint is "done" it is destoyed? The waypoint array would be less 1, or if its the only waypoint the array would be 0. If it is gone, what of its handle or reference?

Meaning, suppose I gave a global variable to the waypoint

objWP = _group addWaypoint [position]

when the waypoint is "done", can objWP "reactivate" the waypoint? Is objWP destroyed? Can I reuse objWP for another waypoint?

So many questions lol.

Share this post


Link to post
Share on other sites

If i understand your problem correctly, you are looking for the format command. Wiki should explain everything good.

Share this post


Link to post
Share on other sites

I've tried format. I understand what it does, just not how to use it with the statement parameter of that command.

Unless I am wrong, what you "type" into that command, the statement part, will literally be what is in the statement of the waypoint.

So if I type "hint 'some text'" it will be the literal same. If I use a variable, such as _Var, the actual statement will have "_Var" in it, not the variable.

So how do you use format in such a case where whatever you put in the statement parameter will literally be the statement and variables will not be expanded to thier values?

Share this post


Link to post
Share on other sites

_objWP setWaypointStatements ["TRUE",format ["hint str ((arValues select %1) select 2);",_int]];

Share this post


Link to post
Share on other sites

Ah! Thank you.

I had it almost right, but your example helped me.

I needed to have

(((arValues select %1) select 1) floor(random(count((arValues select %1) select 1))))

but I was not understanding it. I was thinking something like

((arValues select %1) select 1) floor(random(count(select 1)))

I guess was thinking the first select would follow on out and logically know I wanted to count from the same select. lol. Guess 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  

×