PDA

View Full Version : my lil game



binime
October 25th, 2004, 05:23 PM
well ive spent most of the afternoon touching up the game i want to create and so far it seems to be going well. however, the weapons! big problem! i have an inventory list and everything is working fine, except for one part.



_root.onEnterFrame = function() {
if (Key.isDown(Key.END)) {
weapon += 1;
_root.currentWeapon = _root.weapons[weapon];
_root.char.attachMovie(_root.currentWeapon, "weapon", 1);
if (weapon>weapons.length) {
_root.currentWeapon = _root.weapons[0];
}
}
if (Key.isDown(Key.HOME)) {
weapon -= 1;
_root.currentWeapon = _root.weapons[weapon];
_root.char.attachMovie(_root.currentWeapon, "weapon", 1);
if (weapon>weapons.length) {
_root.currentWeapon = _root.weapons[0];
}
}
};


now the only thing that doesnt work is the attachMovie. when pressing End or Home i want the gun from the variable to be attached to my main character whos Instance Name is "char". everything works good apart from this. can anybody help me please? any help much appreciated
~binime

MichaelxxOA
October 26th, 2004, 12:03 AM
someone please answer this... that is quite scary binime that is nearly the EXACT code I have on mine but it's for choosing attack, but it's the nearly the same all the way down to the variables!! good luck!! I hope you find out!

Dr Warm
October 26th, 2004, 01:34 AM
hmm i think try this (make sure u have linkage names correct:


someAmount = 100;
_root.onEnterFrame = function() {
if (Key.isDown(Key.END)) {
someAmount+=1;
weapon += 1;
if (weapon>_root.weapons.length) {
weapon = 0;
}
_root.currentWeapon = _root.weapons[weapon];
trace(_root.currentWeapon); <-- just to check
_root.attachMovie(_root.currentWeapon, "aWeapon"+i, someAmount);
_root["aWeapon"]._x = _root.char._x;
_root["aWeapon"]._y = _root.char._y;
}

};</pre> the attach movie doesn't actually attach the movie to _root.char, it'll just put it inside of that level (_root.char), and do the same for the home key.

what i actually think you want to do is have the character have a frame where he's holding the weapon, then go to that instead of attaching the weapon

binime
October 26th, 2004, 04:00 AM
what i actually think you want to do is have the character have a frame where he's holding the weapon, then go to that instead of attaching the weapon
cheers ill try that. when i press end or home it cycles through then goes to undefined. any chance of if going to undefined it goes to fist? i have tried many things including


if(_root.currentWeapon == undefined) {
_root.currentWeapon = fist;
}
if(!_root.currentWeapon) {
_root.currentWeapon = fist;
}

Dr Warm
October 26th, 2004, 05:13 AM
<code>if(_root.currentWeapon == undefined) {
_root.currentWeapon = "fist";
}
should work, place it under
</code><code>_root.currentWeapon = _root.weapons[weapon];</code>