Skip to main content
Known Participant
June 21, 2024
Question

flash game inventory issues

  • June 21, 2024
  • 1 reply
  • 287 views

I'm mainly working with an older version. I tried to get the character touch an item which goes to an inventory slot. I got the code off of youtube. For some reason the character won't touch the item as the character just passes it, is something wrong with the code?

 

the symbol and instance of this code is: item

onClipEvent(enterFrame) {
if(_root.char.hitTest(this)) {
_root.addToSlot(this);
}
}

----------------------

the symbol and instance of this code is: itemslot

Inventory Code (Put In Frame):
currentslotnum = 1;
stop();
function addToSlot(item){
if(!item.found){
item._x = eval ("itemslot" + currentslotnum)._x;
item._y = eval ("itemslot" + currentslotnum)._y;
item.found = true;
currentslotnum++;
}
}

-----------------------

the symbol of this code is: character 

the instance of this code is: char

character code:

onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var maxspeed:Number = 10;
var xspeed:Number = 0;
var acceleration:Number = 2;
var maxJump:Number = -15;
var friction:Number = 0.9;
var yspeed:Number = 0;
var bounce:Number = -0.9;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
xspeed *= friction;
if (Math.abs(speed) < 0.3) {
xspeed = 0;
}
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
if ( xspeed < maxspeed ) {
xspeed += acceleration;

}
}
if (Key.isDown(Key.LEFT)) {
if ( Math.abs(xspeed) < maxspeed ) {
xspeed -= acceleration;
}
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed += acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed -= acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += xspeed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
_x += xspeed;
}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 23, 2024

1. that's as2.  are you using an old version of flash (not animate)?

2. do you know how to use the trace function to debug as2?

Known Participant
June 24, 2024

I heard flash 8 was more basic the animate. I tried  to use animate some but it was a little confusing so I tried flash 8 because of the tutorials there. 

Unless theres tutorials here on animate I don't know what to do.

kglad
Community Expert
Community Expert
June 25, 2024

there are lots of animate tutorials.  do you have animate (and a current subscription)?