PDA

View Full Version : [AS2] Selecting a weapon based on a user input


Yacoob
07-09-2009, 12:10 PM
Solved

caffrey75
07-09-2009, 01:18 PM
There are guys on here who would do this a lot better I'm sure but this should be quick and simple to get your head around and implement :)



function setWeapons(myVar) {
//myVar being the number inputted by the user
_root["aaaa"+myVar] = "loc1";
_root["bbbb"+myVar] = "loc2";
_root["cccc"+myVar] = "loc3";
_root["dddd"+myVar] = "loc4";
_root["eeee"+myVar] = "loc5";
_root["ffff"+myVar] = "loc6";
_root["gggg"+myVar] = "loc7";
_root["hhhh"+myVar] = "loc8";

trace(_root["dddd"+myVar]);

}
setWeapons(8);
//so for this you would replace the example 8 in the brackets with _numbox.text;



Hope this helps - it's just set up at the moment so that you can see something being traced out. You'll have to change the "loc1" etc back to how you'd like it ;)

Yacoob
07-09-2009, 01:23 PM
Thanks, and what if it is _root.player.aaaa1?

_root.player["aaaa"+myVar] = "loc1"; <<< You don't put a . after something?

caffrey75
07-09-2009, 01:28 PM
Yup, don't worry about that second '.' Syntax says that you take it off before you put the [] brackets in. I don't know why.

So if it was _root.player.anotherplayer.aaaa1, you'd address it

_root.player.anotherplayer["aaaa"+myVar]

Yacoob
07-09-2009, 03:06 PM
Thanks, it worked perfectly!