LoginLogin

How can i have two loops going at once?

Root / Programming Questions / [.]

Jacklack3Created:
I'm making a fan program to help me focus on projects, and so that i can still look at my 3ds showing a fan sprite. But i want the fan sprite to switch between frames using the SPCHR command and still play the beeps that make the fan sound. So how can i do this?

Instead of making two loops that each do one thing, you should instead think about one loop which does two things (or more). Basically everything in a game can go in one loop. For instance, you can do something like:
WHILE WHATEVER
  CHANGE SPRITE
  PLAY SOUND
WEND
If you only want to play the sound sometimes, you can make a conditional:
WHILE WHATEVER
  CHANGE SPRITE
  IF SHOULDPLAY THEN PLAY SOUND
WEND
Let's say that different sprites play different sounds. You could just use the character ID for the sprite you're setting as part of the check for playing a sound. The bottom line is: don't try to make multiple simultaneous loops. Many things can happen in a loop; you don't have to make a new one for each thing.

Instead of making two loops that each do one thing, you should instead think about one loop which does two things (or more). Basically everything in a game can go in one loop. For instance, you can do something like:
WHILE WHATEVER
  CHANGE SPRITE
  PLAY SOUND
WEND
If you only want to play the sound sometimes, you can make a conditional:
WHILE WHATEVER
  CHANGE SPRITE
  IF SHOULDPLAY THEN PLAY SOUND
WEND
Let's say that different sprites play different sounds. You could just use the character ID for the sprite you're setting as part of the check for playing a sound. The bottom line is: don't try to make multiple simultaneous loops. Many things can happen in a loop; you don't have to make a new one for each thing.
Well the thing is that i want the fan sprite to change every 1 ms, but it would be to hard to go ahead and make the perfect timing in one loop. Plus i dont see how
 while
would help.

You only want to change the sprite once per frame (The screen updates 60 times per second) any more is wasted processing power. If you want an example of managing many objects at once the Space Race program I wrote covers sprites animating many sprites once per 60, 30, and 15 frames per second with sound all at the same time.