Problems implementing a trigger

Started by , Fri 15/02/2008 03:32:57

Previous topic - Next topic

bicilotti

It's late in the night (4:13AM) and I'm running out of coffee (and ideas), however:

In the game I'm writing there's a function which loads a path. A path is just a list of levels with some text to display between them (it is loaded from a file).

Now, my desires for that function are:
1-load the level
2-once the level is finished display some text
3-load the next level..
4-keep doing it

Now, let's focus on the once the level is finished condition: it is triggered by a function (a.k.a. on_key_press) which has nothing whatsoever to do with the first one.

So that's my problem: how can I implement that "once the level is finished" trigger? 

Khris

I'm not sure if I understand this correctly, so I'll go with the easy answer: by using a global variable?

bicilotti

Quote from: KhrisMUC on Fri 15/02/2008 04:19:02
I'm not sure if I understand this correctly, so I'll go with the easy answer: by using a global variable?

The fact is the once i load the level i cannot just check the global against some condition (my condition is "the level is finished", and it can't be when it is just starting). I need something like: "let the game flow (aka let the player play) and, when the exit of the level is reached, load the next one".

Is that possible?

Khris

Definitely.
Code: ags
bool level_finished = true;

int current_level;

// rep_ex
  if (level_finished) {
    current_level++;
    load_level(current_level);
    level_finished = false;
  }

// player reaches end of level
level_finished = true;


You can do it this way, but it's better practice not to use loops unless you have to:
Code: ags
int current_level = 1;

// player reaches end of level
current_level++;
load_level(current_level);

bicilotti


SMF spam blocked by CleanTalk