Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

need help understanding this

i dont get why "gameHasEnded == false" actually makes "gameHasEnded" = true. btw i never learned scripting so it would be kind if one could answer this in a easier way for beginners to understand. thanks a lot!!!


Best Answers

  • PrinceIceYTPrinceIceYT Member
    Accepted Answer

    so i'll try explaining so you get the drill. firist we have the gameHasEnded variable which is a boolean(bool) and it's set to false, which mean the game haven't ended yet. below that we have a function called EndGame which gonna turn gameHasEnded variable to true IF the gameHasEnded is false. now whenever we use the EndGame function its gonna turn gameHasEnded to true. if you asking about why is the if uses the gameHasEnded== false , its because we don't wanna make the game end when it's already ended.

  • SultanSultan Member
    Accepted Answer

    @jerome its quite simple the bool is set to false at the beginning and then you make a public function called EndGame and you might call it from somewhere right? So when the function is called it will check if the EndGame function has already being called (Means the game has already ended ) So the code will not be called mutiple times and if the game hasnt already ended if will call the function And for sure we dont want to end the game multiple times at once 😆.

  • SultanSultan Member
    Accepted Answer

    @jerome No its not like two negative makes a positive or vice versa,its just a simple code read again what I wrote in the pervious comment..

  • Accepted Answer

    no.

    youre seeing if the game hasn't already ended, as they already said. @Sultan said

  • PrinceIceYTPrinceIceYT Member
    Accepted Answer

    @jerome emm gamehasended is a bool set to false. but.. if you use the end game function it'll turn set to true

    owh about the if statement its there so that if the gamehasended is already set into true then it won't set it again to true

  • ZicrusZicrus Member
    Accepted Answer

    gamehasended == false doesn't do anything. It just checks if gamehasended is false. If it is, it uses the code below. Then the code below sets gamehasended to true. So gamehasended == false doesn't set it to true. The code below does

Answers

  • jeromejerome Member

    @Sultan @PrinceIceYT is it like in math two negatives make a positive? i presume the answer is "no", since i tried g{ameHasEnded = true; if gameHasEnded == true gameHasEnded = false} and it functions as same as the code above (changed nothing but swapped the true and false), so if "two negatives make a positive" is true, does this mean "two positives make a negative" in coding?

  • jeromejerome Member

    i understand now, thanks to all of you!!

Sign In or Register to comment.