• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Remove symbol or stop points?

New Here ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

Hello!

I am currently doing game design at university and Have recently started looking at action script 3. I am not struggling too much and can usually find the answer to what I am looking for but this really has me stumped. I want to add an item to a game I am making so that when it is touched it gives some points and disappears. We have been taught to do this (so far) with hitTestObject and I am having an issue where I can get the symbol of the item to disappear but it I stay in the position I keep gaining points. I have tried looking this up but I am not finding anything that works. So any help would be greatly appreciated as I feel like throwing this laptop out of a window right now

This is what I have for my 'coin' right now, please excuse anything crazy as I am only just learning action script and probably have something crazy in there

// if character touches coin
if (thief_mc.hitTestObject(coin_mc)){
if(stage.contains(coin_mc))
removeChild(coin_mc);
// increase points by 5
score += 5;
score_txt.text=String(score);
  

    }

Is there a way to stop at 5 points for the symbol or to remove it to stop any other points being gained?

TOPICS
ActionScript

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 25, 2015 Feb 25, 2015

oh, you're missing a curly bracket:

// if character touches coin
if (thief_mc.hitTestObject(coin_mc)){
if(stage.contains(coin_mc)){
removeChild(coin_mc);
// increase points by 5

score += 5;

score_txt.text=String(score);

}

 

    }

Votes

Translate

Translate
LEGEND ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

I'm guessing that this hitTest is happening inside a for() loop or something similar. If that's the case then you could probably use break; or return(); to get out of the loop.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

something else is causing your points to increase.  use a trace() function to confirm:

// if character touches coin
if (thief_mc.hitTestObject(coin_mc)){
if(stage.contains(coin_mc))
removeChild(coin_mc);
// increase points by 5

trace("coin_mc hit");

score += 5;
score_txt.text=String(score);
 

    }

Is there a way to stop at 5 points for the symbol or to remove it to stop any other points being gained?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

As I suspected when my character is standing where the coin was/is it is continually hitting the movie clip so it keeps adding the points.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

oh, you're missing a curly bracket:

// if character touches coin
if (thief_mc.hitTestObject(coin_mc)){
if(stage.contains(coin_mc)){
removeChild(coin_mc);
// increase points by 5

score += 5;

score_txt.text=String(score);

}

 

    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

Thank you so much O_O I had a very similar problem and because people on my course have the same knowledge as me(ish) I had to wait over a week to see my lecturer to figure this out. Thank you so much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines