I have a situation in my game where I want to get the value of a variable. However, I don't know which variable I want to get the value of. Is there a way to use a variable to select which variable to operate on? For example, if variable 7 is equal to 21, then I want to use variable 21. If V[7] = 22, then I want to use V[22]. And so on.
Obviously, I could just do 12 if statements to get the desired effect, but I'm hoping there's a more concise solution. Being able to use a variable to select a variable seems like it should be a simple thing, but I can't figure out how to do it.
********
I was just about to post this question when I saw the Script Call List thread and decided to dig a bit.
Using a script call, the solution I was looking for is:
$gameVariables.setValue(7,$gameVariables.value($gameVariables.value(7)))
To use examples from my project, V[7]'s value is equal to the current region ID + 20, so in region 1 V[7] = 21 and V[21] = 1. After running the above code, V[7] = 1 as intended.
V[22] = 0 and V[23] = 2, so if I ran the same code in the other regions, I'd end up with V[7] = 0 or 2 as appropriate.
I'm still curious if there was a simpler way to do this that I missed, and I figured that my solution might be helpful to other people, so despite answering my own question I still decided to post this.
Obviously, I could just do 12 if statements to get the desired effect, but I'm hoping there's a more concise solution. Being able to use a variable to select a variable seems like it should be a simple thing, but I can't figure out how to do it.
********
I was just about to post this question when I saw the Script Call List thread and decided to dig a bit.
Using a script call, the solution I was looking for is:
$gameVariables.setValue(7,$gameVariables.value($gameVariables.value(7)))
To use examples from my project, V[7]'s value is equal to the current region ID + 20, so in region 1 V[7] = 21 and V[21] = 1. After running the above code, V[7] = 1 as intended.
V[22] = 0 and V[23] = 2, so if I ran the same code in the other regions, I'd end up with V[7] = 0 or 2 as appropriate.
I'm still curious if there was a simpler way to do this that I missed, and I figured that my solution might be helpful to other people, so despite answering my own question I still decided to post this.