Coin value doesn't increase and doesn't disappear upon pickup
Hi,
I want to add a scoring system to my game, so upon pickup of the coin, it disappears, +1 to the Score. I've got the coins inside my background symbol and then another symbol used for miscellaneous things on the bground and it doesn't work in there, as I get the error 2007 - Parameter hitTestObject must be non-null, but when I take it out of this symbol and onto the main game, it works, but as the player moves, so does the coin. How do I make it work inside the symbol?
This is the code that I've got for the coin. I've gotten this from another tutorial, and I tried to follow the layout of the code for the key below, however, the code for the key is working, and this isn't.
var score=0;
if (player.hitTestObject(back.other.coin)) {
score++;
coins_txt.text=score.toString();
back.other.coin.visible = false;
}
This here is showing something similiar that I've got, a key, which I'm able to collect and it disappears when I do. This is basically what I want with my coins, with the addition of adding +1 to the current score.
if(keyCollected == false){
if(player.hitTestObject(back.other.doorKey)){
back.other.doorKey.visible = false;
keyCollected = true;
trace("key collected");
}
}
So far, I've tried Googling the error but I couldn't find anything useful apart from the fact that adding a brace somewhere may fix it, but I don't really know where, and also looked at different ways of doing it. Originally, I had the code for the coin in a Class which I linked to my main game afterwards, but I had a similiar problem there. I've also made sure that the coin has an instance name of "coin".
Does anyone have any suggestions how to fix this?
Thank you
