Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hello, I have some variables in the game like: var near1 = 0;which I use to let the system understand when I am near an object ( 0 = not in the object radius area 1 = in the object radius area ). Now because I have like 30 variables like this, I don't want to copy paste the same code 30 times... Is it possible to use wildcards? I think something like this: So in this case when I'm near the object 2, the overlay2 will be visible, when i'm near the object 4, the overlay4 will be visible, etc... If you need me to explain better what I want, please ask... I would really appreciate if someone will help. |
||||
|
No, but you can do this using arrays. Similar to what you suggested. Somewhere in the beginning of your game, initialize the array with this: var nearTester = new Array(); and set the content with this: nearTester[1] = 1; and , then you can test using if (nearTester[1] == 1) ... |
||||
|
Hi niko and thank you, but wouldn't it be the same like now? Because if I use arrays like you suggested, I will have to copy the code 30 times: if (nearTester[1] == 1) ...So it would not semplify it... I'm looking for a better solution that would make me write the code only once, and even if I add other objects in the game, I don't need to add more code. |
||||
|
????? You can cast all object in scene and get distance from player ( calculate hypotenuse ) and know this var... don't need make many code.. not more 6 lines ( i think ).. |
||||
|
You can use a loop and go through an array. Like this: for (var i=0; i<nearTester.length; ++i) |
||||
|
Thank you all! Erik, I tried your way to (for loop and go through array) and it worked perfectly! Thank you!!! |
|