- Home /
String Access problem
Hi community,
I have such a problem:
I have a code such:
var question = 0;
var val1 ="Sıfır";
var val2 = "Nul";
var val3 = "Bir";
.
.
.
Till 405 numbers
And I will random a number:
question = Random.Range(1,405);
And I want to print one of them such as like:
print("val"+question);
So I want to return the value of for example val2 and the printed one will be "Nul"
But always the returning result is such as "val40", "val3"... instead of "Sifir", "Bir"
How can I access the variable in those strings with such an example of this print example?
I will put around 3000 values so is is not a good idea to use if comments that will make my job so hard.
Sorry for my writing that I dont know how to write proper in Answers, and thank you for your help from now
question here is an integer are you are trying to print string with it...
Answer by crazyKnight · Jun 10, 2011 at 10:22 AM
Why dont you use an array for the val declaration,because what you are doing is completely illogical, try something like this
var val : String[]; //declare these values in the inspector
private var question : int;
function Update()
{
if(print) // your condition to print
{
question = Random.Range(0,val.length);
print("val "+val[question]);
}
}
Thank you very much Now I see I was using the wrong approach
Your answer
Follow this Question
Related Questions
Setting float variable to an Array value 1 Answer
how to randomly pick a string from an array 3 Answers
Referencing private string for array name 2 Answers
How to randomize an array of Strings? 2 Answers
Assigning array element to variable 1 Answer