Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.23 / 5.00 3,881 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.93 / 5.00 4,634 ViewsI want to set 30 kinds of weapons that have different name as variables.
For instance, I'd like to use variables to judge whether player
has aquired the weapons. ( 0 for not aquired, 1 for aquired)
weapon1 = 1
weapon2 = 0
weapon3 = 0
..... And so on
I don't want to repeat weapon4 weapon5 weapon6 all the way
up to weapon30 because it's waste of time.
I know this can be done fast by using for statement
but I dunno how exactly to.
Can someone show me a way to do this?
w
You could just store the true/false in an array
var weaponArray:Array = [true];
for( var i:int = 1; i < 31; i++ )
{
weaponArray[i] = false;
}
// Saying you've aquired first weapon, but no others.
//Then to check
for( var k:int = 0; k < 31; k++ )
{
if( weaponArray[k] )
{
unlockWeapon("weapon"+k);
}
}
Is that what you meant?
Want to increase knowledge in programming. If you need someone to program something, I will be happy to help for free :) .
Arrays. Learn them, and learn them well.
You essentially want to create an array with 30 elements:
(also, you should use 'true' and 'false' instead of 1 and 0)
var weapons:Array = new Array(30);
weapons[0] = true; // set the first weapon to true, notice arrays begin at 0, and not 1
// set the rest to false
for (var i:int = 1; i < weapons.length; i++) {
weapons[i] = false;
}
Then later you can do stuff like set the 15th weapon to true, as an example:
weapon[14] = true; // the 1st element is 0, therefore the 15th element is 14
And if you want, loop through them all again somewhere else and do something with each value:
for (var i:int = 0; i < weapon.length; i++) {
// do something with 'weapon[i]'
} #include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}