Quick question about code

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?
int main()




Serious stuff aside, you have two options: multiple threads or cooperative multitasking via the wait functions.

What exactly do you wish to accomplish?
I want to have a code to be continually running independently without being affected by options 3 and 4.

Kind of continuously looping whether option 3 or 4 is chosen
Last edited on
I'm not so stupid that I didn't understand that much the first time through.

Unless you can give me something more specific than a very, very general description, then I cannot offer better advice than I have already given you.
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 ...

Etc. Hope this helps.
Okay I see.

Thank you,
Topic archived. No new replies allowed.