Great so that all works perfectly. But Say If want to check if a user has a certain item if so…such an such happens…etc. But I can’t figure out how I would do this with an If statement. No matter what I can’t get it to work( That is what you’d use right?). Can anyone tell me the best way to do a “check” for this type of thing. Thanks in advance :).
inventory = new Array();//inventory array to store the items collected
Array.prototype.find = function(item) {//prototype to search for a string inside an array
var found = false;
for (var i = 0; i<this.length; i++) {
if (this* == item) {
found = true;
}
}
return found;
};
function addToslot(item) {//function to add item to the inventory
if (!inventory.find(item)) {//if the item isnt already in the inventory
inventory.push(item);//add the item to the inventory
}
}
stop();
And on your item:
onClipEvent (enterFrame) {
if (_root.character.hitTest(this)) {
_root.addToslot(this);
}
}
Okay…but how is that any different than my script…I mean it just allows me to add stuff to my inventory…With the above I can’t check if I have specific individual items, and in turn get flash to execute certain things can I? Perhaps you could give me an example .fla because I don’t see how that allows you to check stuff :h:
Alright, if the character thing touched any item that’s collectable, he obviously has it because in your code, any item touched goes to the inventory. So in your main code, add another function like so:
function itemCheck () {
// The bottle is an example item:
if (_root.character.hitTest (_root.bottle)) {
// Do Something Here:
}
if (_root.character.hitTest (_root.car)) {
// Do Something Here:
}
}
setInterval (itemCheck, 0);
So basically, this code keeps checking if certain items are touched, and if they are, an action is performed (which you have to assign).
but as far as I can understand your code claudio…If you don’t have the item when the script checks for it, it will push it into your inventory anyways? How would that work???
As for you suggestion, Sharif I understand how that would work but that wouldn’t help you actually have the ability to say if you have a certain item in your inventory you are then allowed to perform another action.
Then you are not understanding the code. If the character hittests the item, you perform the checking. If the item isnt already in the inventory, then add it.
[edit]ops, the enterframe should go on the item, not the character[/edit]