Sign in to follow this  
Foobar

I need you.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.