Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Can I use a variable in another variable name?

$
0
0
I have a quick javascript question. I'd like to use a variable as part of another variable name. I have 4 players. And a variable, `playerSelected = 1` (2, 3 or 4). I also have variables such as: player1Sword = 1; player2Sword = 0; player3Sword = 0; player4Sword = 0; Rather than doing... `if (playerSelected == 1)` etc for each player, I'd like to do something like: player[playerSelected]Sword = whatever Is that possible?

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>