Hello, I am new to these forums and I have a quick question about code.
Let's say I have this code and I have a bit of that code to be continually running
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void main()
{
code1 with 2 options
option1
{some code for more options
code that I want to run continuously if option1 is chosen and without interfering with options 3 and 4
option3 {more code}
option4 {some code}
}
option2
{some code}
}
would that work?? or do I have to do something special or running each time in each of my options?
Well basically I'm doing a text-based console RPG.
So I want my level up code to be repeating so I don't have to put it after each battle. But in my game you choose characters at the beginning and they have different codes , so I don't want to put after each battle like this:
1 2 3 4 5 6 7
}//end of battle
//level up
if (character == 1) {levelup1}
if (character == 2) {levelup2}
if (character == 3) {levelup3}
if (character == 4) {levelup4}
I want it to be always looping all through the game
Ah, well, you are actually doing it more or less the right way.
There should be a main loop that controls your gameplay somewhere. It goes in that loop. It might be worth putting all the specifics in a function, so all you need to do in the loop is call the function once every time through.
A multitasking/threaded approach is more for things that have to work concurrently, not to just happen at specific intervals as you are doing.
main:
do:
initialize
playgame
finalize
while (user wants to play again)
playgame:
do:
take turn
update_environment
update_enemies
update_characters
...
while ...