This content has been marked as final. Show 9 replies
you made the newname string local to tokens() when you prefixed it with "var". outside tokens() (and in particular, inside collectToken() ), newname is undefined.
to remedy, remove the "var" prefix your newname assignment statement.
Thank you kglad for your reply.
Unfortunately, when I alter the code according to the instructions above I get the following:
The collectToken function seems to execute automatically. I think this because even though the tokens don't 'appear' on stage (I think they are being removed as soon as they are created) the score increments each time one is created even though my skater mc is nowhere near it.
I thought it might be a problem with my 'if statement'
if (_root.skater, hitTest(_root[newname]))
but altering it doesn't produce the desired result.
If you or anyone else could help me through again, I would greatly appreciate it.
there's nothing calling the collectToken() function in the code you posted. so, you must have code elsewhere causing that problem.
however, your hitTest() syntax is incorrect. use
Thank you again for your response kglad
I'd previously substituted the above code in the actionscript before I posted the reply so the problem may be the way I call the function. (Substituting the above code gives me the original problem - no hitTest detection.)
I've posted the function calling the collectToken function code as it isn't that long for you to look at.
_root.hp = 100;
var numToken = 3;
var timeSinceLastToken = 0;
score = 0;
_root.onEnterFrame = function()
gutter._x -=5; // moving the gutter
once again, I've probably just structured it wrong but I figured it's worth you looking at it.
Please note that the 'bail' function is the game over side of things
Thanks again - I truly appreciate the help
that looks a little screwy. every 200 loops or so of your onEnterFrame loop you're creating a new token and then checking a hitTest on that one, just created, token. is that what you want?
What I'm trying to do is build a simple platform game about a skater, who rolls over tokens to collect them to add points. I basically want the following:
1. The tokens randomly appear at the far right of the screen.
2. As they appear, they "move" towards the left of the screen (this is in line with the background, which also moves across the screen giving the skating movement illusion. (I haven't gotten to this bit yet!)
3. As soon as any token is touched by the skater, it is removed from the stage and the score is incremented.
4. if the skater misses a token and it goes off the other side of the screen it is 'lost' - you can't go back and get it.
Could you please if it's not too much trouble just explain to me where in the code I've told it to check just that one token?
Thanks so much for taking the time to look and answer.
collectToken() is only checking one hitTest(). it checks frequently but it's only checking the last created token. if that token is "lost", it's still checking. if there is more than one token on-screen, it only checks the most recently created one.
Thanks so much kglad. I guess I have to go back and rethink my code. Dammit!!!!
I appreciate you taking the time to answer my questions. If you have a suggestion on code structure (some sort of pseudocode) that could point me in the right direction, I'd also appreciate it.
Thanks again for all your assistance.