00:00
00:00
Newgrounds Background Image Theme

TheADHX just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Trouble With Inventory

683 Views | 3 Replies
New Topic

Trouble With Inventory 2013-02-20 17:09:58


So I am making a point and click game and my inventory system wont work. I basically used the same technique that a tutorial showed me on NG.

empty = 0;
t=0;
i=0;
_root.inventory = [_root.slotA];
for(i=0;i<4;i++){
_root.inventory[i] == 0;
}
if (_root.inventory[i] ==0){
_root.inventory[i].gotoAndStop(1);
}
gun.onRelease = function(){

_root.gun.unloadMovie();
while(t<5 && empty == 0){
if (_root.inventory[t] == 0){
_root.inventory[t].gotoAndStop(2);
_root.inventory[t] == 1;
empty = 1;
}else{
t ++;
}
}
}

What I tried to do:

Make every inventory slot == 0;
If a slot is equal to 0, then it would stop on an empty frame

Then after clicking the gun:

Search through each slot, if one of them was equal to 0 (on the empty frame)

that slot would go to frame 2 (picture of a gun)

Then, because empty = false, the search would stop.

After fiddling around with the code I noticed whenever I put in an IF statement the code wouldn't work. There was no issue with the arrays or anything (I tested the code using arrays and no IF statement and it worked.)

Can anyone help me?

Response to Trouble With Inventory 2013-02-20 18:43:17


Realized my error, it was really stupid of me, I changed the whole value of the variable. I need to find another way.

Anyway can this thread be locked or deleted? Thanks

Response to Trouble With Inventory 2013-02-20 18:57:02


At 2/20/13 06:43 PM, cheese123 wrote: Realized my error, it was really stupid of me, I changed the whole value of the variable. I need to find another way.

Anyway can this thread be locked or deleted? Thanks

Fixed code for anyone interested:

empty = 0;
t=0;
john.text = empty;
_root.commentary.text = "I saw him go through here...";
_root.inventory = [_root.slotA];
gun.onRelease = function(){
while (empty < 1){
if (_root.inventory[t]._currentframe ==1){
empty ++;
_root.inventory[t].gotoAndStop(2);
_root.commentary.text = "That's strange, it was just lying on the floor.";
_root.gun.unloadMovie();
}
else{
t ++;
}
}
}
fence.onRelease = function(){
_root.commentary.text = "It's locked.";
}

Response to Trouble With Inventory 2013-02-21 11:06:16


Closed since the OP's problem has been resolved, and this was posted in the incorrect forum; please keep ActionScript related threads in the Flash forum.