Changing variables in loops

Hey, I can completely understand what you mean but I still don’t understand how I can write this code? I basically want it so that when the player died, the score is added to the amount of coins they have, but the current problem is that when the died variable = 1, it is constantly adding the score to the coins variable. How else would I write this?

Thank you so much for your help!

If you are wondering why I am wanting to know how to do this it is because I am currently doing a lua assignment at college and need to make a game. I can email you my main.lua file if you wish. Thank you again!

Why don’t you just do this at the point died is set to 1?

If you must do it within your gameLoop, have another flag ‘handledDeath’ that you set after the first run through after died = 1, and check that both died = 1 and handledDeath = 0.

I would personally use true/false (Boolean) rather than 1/0, as this allows easier to read code such as ‘if died then’ or ‘if playerIsReady then’.

Helping people do their college work is getting dull real fast…

It does seem they teach people the code needed to do X in isolation, but not how to think like a programmer. Which is surely the biggest thing you can take away from a one-off development module, as the syntax is quickly going to be forgotten if not used regularly.

@decoder,

  1. Please do not hijack threads.

  2. See your other post for answers about scope and visibility as well as declaration order…

Ok bro…I didn’t know where to post…This won’t happen again…!

@decoder143, if you can’t find an appropriate forum post that answers your question, you should search for a forum post that is asking the same question if you need some additional clarification. If you can’t find an appropriate thread then start a new one!

When you post a different topic on an thread that isn’t what you’re discussing it does two things. First people see the headline/subject and its about topic X they won’t have a clue that topic Y is being discussed.  The second issues is people who come looking for Topic X to learn more about that problem find a thread talking about topic Y get frustrated because this isn’t the information isn’t what you’re looking for.

Rob