A mechanic I created leads to an infinite loop and I need a workaround

Reposting this from my WIP thread to get relevant attention (the issue is explained fully in the post).

1 Like

Your else statements for if the roll is greater than 81 look off–they’re currently never being called. I think you want something more along the lines of

*if (event_choice = 1) and (event_1 = 0)
   *set event_1 1
   *goto event_1
*if (event_choice = 2) and (event_2 = 0)
   *set event_2 1
   *goto event_2
   *goto event_reroll

Yeah that’s a typo on my part.

I’m on mobile currently so I couldn’t do a direct copy/paste from the original code on my computer.

The code in the post is just a rough sketch from memory of what is actually being used.

Once you settle on the number of events you could add a variable called like numofevents and increment it every time an event is picked and then if numofevents = 20 you skip the roll and go to galaxy map?

I considered that, but then comes the next issue:

Some events will have certain pre-requisites before they become available to play (for example, there can’t be an interaction between two characters if one or both of them were never met and/or recruited by the player).

So, if the player never achieves all possible pre-requisites before rolling a successful event_roll, the event-counter-thing won’t work.

Instead of checking it against a flat value like 20, you could check it against a variable that dynamically updates based on what events can occur, but I agree we’re a bit in the weeds here. I’ll keep thinking :slight_smile:

1 Like

Maybe a temporary solution would be to check it against the number of re-rolls instead?

So, for example, every time I hit *goto reroll, I’ll do something like *set roll_count + 1. Then if roll_count hits say, 10 rolls without finding an available event, it’ll abandon the attempt and move on to the Galaxy Map?

It’s not perfect for what I’m looking for since it can still skip available events, but it’ll at least prevent the infinite loop and cut-down on redundant rolls…

1 Like

How is it that people will be accessing the random scenes? If the ship has different areas, perhaps the random scene selection can trigger when entering certain rooms/areas of the ship, giving people a chance to re-enter and get the prerequisite scenes for the later ones.

Well, the way I have it planned currently is like this:

Every time the player chooses to access the Galaxy Map (which is essentially the only way to actually progress the game, so it’ll be accessed quite often) the event roll happens.

Then, depending on which event_choice the second roll picks, an event will take place that interrupts the player from getting to the map. (For example, a character will stop you to draw attention to a conflict they’re having with another character, or maybe you’ll hear an unusual noise from another room, giving you a reason to stop and investigate).

That “interruption” event won’t always lead straight into a scene. Often times, I’ll give players the option to ignore it until a later time.

This is where “event_1 = 0” becomes useful. When I set it from 0 to 1, the game tracks that the interruption has occurred, (so the re-roll will prevent it from happening again) BUT it registers that you haven’t chosen to investigate further yet. Thus allowing players to ignore it and deal with it at a later time of their choosing.

Upon investigating, I’ll *set event_1 = 2. This will then remove the option to investigate the same event twice, thus completely ending that specific event.

Edit: The reason I don’t have the event roll trigger at each room it might take place in is simply because it’s much more organized (and easier to find bugs) if the trigger is always in the same place.

I don’t know much about CS, but you can use boolean variables (true/false) for each event.


*create event_1 false
*create event_1_investigate falae

And when the roll draws that event, you could do this;

*set event_1 true
*set event_1_investigate true

Hope that helps!

1 Like

What do you want to happen if all the random events are exhausted? You need a “catch all” condition in that case.

*label event_reroll
*rand event_choice 1 2
*if (event_choice = 1) and (event_1 = 0)
   *set event_1 1
   *goto event_1
   *else                                       <<<[C]
      *goto event_reroll
*elseif (event_choice = 2) and (event_2 = 0)   <<<[A]
   *set event_2 1
   *goto event_2
   *else                                       <<<[C]
      *goto event_reroll
*else                                          <<<[B]
   *goto lsakdfdj

A. You want to swap all *if instances below the first one to *elseif for the purpose of,
B. *else to be useable. This is your catch-all condition. Lastly,
C. Your *elses here would produce an error as there’re no starting conditional checks preceding them.


To elaborate further on what @Szaal has said, try something like this:

01: *choice
02:	  #Go to the Galaxy Map
03:		*gosub event_roll
05:		*if (event_roll <= 80)
06:			*goto galaxy_map
08:		*elif (event_roll >= 81)
09:			*rand event_choice 1 num_total_events
10:			*label event_reroll
12:			*if (event_choice = 1)
13:				*if not(event_1)
14:					*set event_1 True
15:					*set num_events_visited +1
16:					*goto event_1
18:				*elif (num_events_visited < num_total_events)
19:					*set event_choice +1
20:					*goto event_reroll
22:				*else
23:					*finish
25:			*if (event_choice = 2)
26:				*if not(event_2)
27:					*set event_2 True
28:					*set num_events_visited +1
29:					*goto event_2
31:				*elif (num_events_visited < num_total_events)
32:					*set event_choice +1
33:					*goto event_reroll
35:				*else
36:					*finish
38:			*elif (num_events_visited < num_total_events)
39:				*set event_choice 1
40:				*goto event_reroll
42:			*else
43:				*finish
46: *finish
47: *label event_roll
48: *rand event_roll 1 100
49: *return

I haven’t tested it but it should be working.

Notice that you’ll need two extra variables, num_events_visited will keep track of how many events have been visited and num_total_events is a constant with the total number of events.

The code appears to be redundant but it makes it more procedural. It means that in the future when you add more events, just copy the same pattern and insert them before the last elif in the stack, this one: *elif (num_events_visited < num_total_events).

Also, I used the *finish statement as placeholders, you may want to replace with a *goto.

What this will do is randomly pick an event, if the event has already been visited, then it goes directly to the next available event. When all events have been exhausted, then it terminates the routine.


I… think that would work? I’ll give it a shot and see what happens :sweat_smile:

1 Like

the code is quite good, ich would think about adding the prerequisites directly to this code, so that events whos requirements are not matched would also not get chosen.


Right, only issue is… I don’t yet have the prerequisites (or even the related characters/events) written up yet (still under development). I’ll definitely be adding onto the code as I go, though.


These could of course be added later, but having them in the first line, where gets tested if a condition fits, makes it unnecessary to have a come back to the event later loop, and the easier the code is, the easier mistakes are to spot^^

I have also played with a eventlist, but I did not tried a random one, it is definetly an interesting concept.


It’s an idea I stole from some classic role-playing-games. (Fallout, ElderScrolls, RuneScape, and countless others) Basically, it makes the world feel more “active” and not necessarily centered entirely around the player (even though it’s the player’s choice(s) that trigger them, ultimately)

And obviously, provides opportunities for character development and lore-building.

I know you said you have conditions to trigger the availability of the event, but I would just like to point out that CS has a command *goto_random_scene in which you can list a series of scenes and the command will pick a random one. It will avoid scenes already visited in subsequent calls, until all scenes have been used.

Unfortunately it does not allow extra conditions nor to set variable values.


Yeah, that also requires creating separate scenes for each event. Since they’re going to be small, that would be sort of a waste, imo.

I’d rather not have too many near-empty scenes.

Though, it may be useful for more significant events.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.