Jump to content
Sign in to follow this  
Toasted Duckie

strings, numbers, variables and a good headache.

Recommended Posts

Hello once again.

Imagine someone wanting to "automate" the following process (assigning variables to something);

_var1 = variable1;
_var2 = variable2;
_var3 = variable3;

I've been struggling for a while now, but the code below shows up a hint every 2 seconds saying: _var1 . 2nd time it says _var2 and 3rd time it says _var3.

_max = 19007;
_min = 19004;
_var =  "_var";
_Add = 0;


while {(_min <= _max)} do
{
_Add = _Add + 1;
_var = format ["_var %1",_Add ];
hintSilent format ["%1",_var ];
_min = _min + 1;
sleep 2;
};

In other words, I can let the variables (_var1, _var2, _var3) show up. But I can't get a "hold" of them to assign anything to them.

If that makes sense :confused::confused:

Help much apreciated:D

<3

Share this post


Link to post
Share on other sites

_min = 19004;
_max = 19007;
_add = 1;
for "_i" from _min to _max do {
 call compile format ["hintsilent _var%1",_add];
 _add = _add + 1;
};

Edit: You said you have 3 variables, but min - max contains four. So, you might need to tweak it a little. For example, not including max:

_min = 19004;
_max = 19007;
_add = 1;
for "_i" from _min to (_max - 1) do {
 call compile format ["hintsilent _var%1",_add];
 _add = _add + 1;
};

Edited by Shuko

Share this post


Link to post
Share on other sites
_min = 19004;
_max = 19007;
_add = 1;
for "_i" from _min to _max do {
 call compile format ["hintsilent _var%1",_add];
 _add = _add + 1;
};

Unless I'm misinterpreting you, you are misinterpreting me:)

I want to do:

_varx = (variable)

where _varx is the text coming up in the hint. It's been too much of a struggle to properly explain it... I just can't think of a better way to explain, my apologies:D

Share this post


Link to post
Share on other sites

_var1 = "one";

_var2 = "two";

_var3 = "three";

Then that code will hint:

one

two

three

Share this post


Link to post
Share on other sites

I don't want the hint to show the variables, I want to create variables with the variable name as showed in the hint.

Share this post


Link to post
Share on other sites

Ah ok.

Two stupid questions:

1) Why can't you just use the global variables in your script?

2) Why can't you use an array?

Share this post


Link to post
Share on other sites
Ah ok.

Two stupid questions:

1) Why can't you just use the global variables in your script?

2) Why can't you use an array?

1) More instances off the script will be running

2) the script is pretty dynamic, amount of elements aren't a fixed value

Share this post


Link to post
Share on other sites

If you have a string containing the variable name, you can assign a value like this:

call compile format ["%1 = VALUE",_varString];

Where VALUE is any value, and _varString is your variable as a string (ex: "_var1"). Or, if your value is also a variable:

call compile format ["%1 = %2",_varString,_value];

Same story, only _value is another variable containing the value.

Share this post


Link to post
Share on other sites

1) Guessed as much.

2) Kind of hard to think of what you can't do with nested arrays.

---------- Post added at 07:47 PM ---------- Previous post was at 07:24 PM ----------

Same story, only _value is another variable containing the value.

Except it's a bit more trickier with wanting to assign local variables as you need to have the call compile format actually return value, because it doesnt help to assign value to _var inside it as it will not exists in the main scope/script. It's usually simple, but wanting the receiving var name to be dynamic makes it just a mess. :P

Share this post


Link to post
Share on other sites
Except it's a bit more trickier with wanting to assign local variables as you need to have the call compile format actually return value, because it doesnt help to assign value to _var inside it as it will not exists in the main scope/script. It's usually simple, but wanting the receiving var name to be dynamic makes it just a mess. :P

What about:

private[_varString];
call compile format ["%1 = VALUE",_varString];

Share this post


Link to post
Share on other sites

Yep, that helps, but you probably need to first loop to create the varnames, then private them, then do another loop to actually assign values since most likely it does no good to private them inside the same loop, because they wouldn't be visible for the upper scope. :)

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  

×