Sign in to follow this  

Recommended Posts

 

Hello, here I created game but I have a problem with a function. When did the party begin to have a message that says "Go!" and I would like it to change when the player reaches 100 points. My last try script that absolutely does not work.

function textChange() {
    updateScore();
    if (player.score == 100) {
        updateText("Good!");     
    }
}

Thanks all

Share this post


Link to post
Share on other sites

What does the `updateScore` function do?

When do you call `textChange`?

How I imagine something like this would work:

* Game renders

* User input, play the game

* Game renders, this top bit is a loop

* When the user does something, then somehow you update the score, maybe you call `updateScore`?

* When the score has been updated you want to check if you should change the text, maybe by calling 'textChange`?

* This checks the current score and calls `updateText` if necessary

* As the game is on a loop, the game will render and the text on screen will have changed

There are lots of ways to accomplish the above steps, but I imagine pretty much any way of doing it will do roughly those steps, probably in that order.

I think that maybe you're not calling functions in the right place, or, more accurately, at the right time.

Share this post


Link to post
Share on other sites
On 23/04/2018 at 11:17 PM, mattbnn said:

If player can get more than one point in updateScore() you probably omit 100 score

change to:


if (player.score >= 100)

My thoughts exactly! It might be the case that your update loop goes too fast and therefore indeeds reaches more than 100.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.