TheMcDeth 0 Posted January 13, 2004 I tried combining names in a script as follows <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> target="v"+format["%1",raah] raah is an integer from 1 ... 10 I then have 10 different objects in a mission named from v1 .. v10 I then checked that the combining of the number and letter is correct in hint dialog <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format["%1",target] When I try to use the "target" variable in another command I get an error message about the variable being a string and not object. So my question is can I change a type of a variable from string to object? Or are there any other possibilities to achieve the same Share this post Link to post Share on other sites
Hakon_H 0 Posted January 13, 2004 dont know exactly but u cant try Quote[/b] ]_targetname = format ["T72"] Share this post Link to post Share on other sites
Hakon_H 0 Posted January 13, 2004 forgot then u hint format["%1",_targetname] Share this post Link to post Share on other sites
tracy_t 0 Posted January 13, 2004 I tried combining names in a script as follows<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> target="v"+format["%1",raah] raah is an integer from 1 ... 10 I then have 10 different objects in a mission named from v1 .. v10 I then checked that the combining of the number and letter is correct in hint dialog Why concatenate strings that way? This is better code. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _target = format["v%1", raah] hint _target And then use object _target to create an object reference. If that doesn't work, you're screwed Share this post Link to post Share on other sites
TheMcDeth 0 Posted January 13, 2004 Thanks. I have to try it when I get back home in the evening. I thought there must be easier way than what I was trying. Share this post Link to post Share on other sites
Sgt_Wilson 0 Posted January 13, 2004 Use the call command to return the value of a variable from a string. I think it works like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _Target=format["v%1",raah] _CurrTarget=Call {_Target} So if raah equals 1 then _Target="V1". The call command executes a function that returns the value assigned to the variable V1. Share this post Link to post Share on other sites
suma 8 Posted January 13, 2004 I think what you mean is more like: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Target=format["v%1",raah] _CurrTarget=call _Target _Target is a string and if you enclose it in double quotes, the result of evaluation will be value of _Target (the string), not the object with the name given in _Target. Share this post Link to post Share on other sites
tracy_t 0 Posted January 13, 2004 So to summarise: use object _varname to get an object reference and call _varname to get the value of a "calculated" named variable at run time. Might be one for the FAQ, this? Share this post Link to post Share on other sites
crashdome 3 Posted January 14, 2004 Not to beat a dead horse, but this is a single line format I use quite often when needed (using first posts vars): call format["target = v%1",raah] EDIT: Must mention that "target" variable MUST be declared prior to this line being executed for it to remain in top scope level --- example again: target = objNull . . {bunch of code} . . call format["target = v%1",raah] Share this post Link to post Share on other sites
TheMcDeth 0 Posted January 14, 2004 Thanks to all who helped me. I reduced the length of one code to about 15 % of the original. When I use the same code in many missions I now have a very easy job of editing the code for each mission. Share this post Link to post Share on other sites