- Home /
2 small questions about scripting
Hello,
I am using MonoDevelop, and I have 2 small questions :
Why sometimes MonoDevelop allows me to shrink a function (with the small - / + in the left margin) and sometimes not ?
Is there a way to have a variable name containing a variable ? For example, I need to get characteristics from a character database, and I would like to store them into this kind of variable : static var Toughness_5:int (with 5 = id of the character)
Thank you,
Pierre
This is two different questions, one of which is significantly more complex than the other. Can you explain a little better what you mean by that variable thing? Do you want the variable name to depend on some other value?
The usual object-oriented way of doing this is to have 5 different characters, and to just use
character5.toughness
ins$$anonymous$$d of having a whole bunch of different things which do almost the same thing as each other.
Well, I think in PHP it works like this :
for ($i=0, $i<10, $i++)
{
$name = "variable_"+$i;
$$name = "myvalue_"+$i;
}
And I shall have :
$variable_1 = myvalue_1
$variable_2 = myvalue_2
etc.
I just want to know how it works in unity to have this " $$name "
99.9% of the time you should use arrays or other collections ins$$anonymous$$d of trying to literally use "toughness_5" and so on as variable names.
$$anonymous$$$$anonymous$$h I guess you are right, I will try to think about it. I'll close this question, and I'll hope I'll find a solution for shrinking my functions ^^
Answer by Aralox · Dec 10, 2011 at 12:51 PM
Hi there, Im not sure about the first question, but im guessing if you save your scripts and reopen them with monodevelop you should be able to fold (use +/-) on all your functions.
Aso for your second question, read up on arrays, sounds like just what you need - eg have a toughness array, where you can access toughness[5] (or loop through the array, etc).
If you want a really good, thoroughly explained introduction to scripting, check out the walker bro's tutorials.
Good luck :)
Even after saving, I cannot fold some functions. What is strange is that I can hide some of them, but not all (about 20%).
Your answer
![](https://koobas.hobune.stream/wayback/20220613061943im_/https://answers.unity.com/themes/thub/images/avi.jpg)