Foobar Posted April 21, 2018 Share Posted April 21, 2018 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 Quote Link to comment Share on other sites More sharing options...
mattstyles Posted April 22, 2018 Share Posted April 22, 2018 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. Quote Link to comment Share on other sites More sharing options...
mattbnn Posted April 23, 2018 Share Posted April 23, 2018 If player can get more than one point in updateScore() you probably omit 100 score change to: if (player.score >= 100) TheBoneJarmer 1 Quote Link to comment Share on other sites More sharing options...
TheBoneJarmer Posted April 26, 2018 Share Posted April 26, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.