In your startup.txt you include these lines:
*create Steve_relationship 0
*create Sarah_relationship 0
*create Sam_relationship 0
*create Sean_relationship 0
*create Highest_relationship " "
*create Highest_relationship_stat 0
Then create a new file, let’s call it ‘high_relationship_calc’ and put in this code:
*if Highest_relationship_stat = 0
*set Highest_relationship "Steve"
*set Highest_relationship_stat Steve_relationship
*if Steve_relationship > Highest_relationship_stat
*set Highest_relationship "Steve"
*set Highest_relationship_stat Steve_relationship
*if Sarah_relationship > Highest_relationship_stat
*set Highest_relationship "Sarah"
*set Highest_relationship_stat Sarah_relationship
*if Sam_relationship > Highest_relationship_stat
*set Highest_relationship "Sam"
*set Highest_relationship_stat Sam_relationship
*if Sean_relationship > Highest_relationship_stat
*set Highest_relationship "Sean"
*set Highest_relationship_stat Sean_relationship
*return
Then go about making your scenes, you get to scene 20 where you are at a party and the MC does something and needs help. You need to pick an RO to go over and assist:
You pick up the glass and drink it. Oh no, it's actually poison. You need help!
*gosub_scene high_relationship_calc
*if Highest_relationship = "Steve"
*goto_scene steve_assists
*if Highest_relationship = "Sarah"
*goto_scene sarah_assists
*if Highest_relationship = "Sam"
*goto_scene sam_assists
*if Highest_relationship = "Sean"
*goto_scene sean_assists
So, in your startup you define the 2 types of variables you need:
- One relationship variable per RO
- The RO who has the highest relationship stat and what that stat is
Here we default it to an empty string and 0. This is fine as we’re going to override it the first time we calculate the actual RO with the highest value.
Let’s skip to our scene next. We have some text and then we want the computer to pick an RO. Here we just ask if the Highest_relationship is equal to each RO in question. It will be only equal to one of them, and that is the route we follow (the simplest outcome being to play a bespoke scene for that RO).
To calculate which RO is actually the highest, we call the subroutine first (*gosub_scene high_relationship_calc). This calls the file (scene) with that name and just runs the code within it. This code doesn’t display anything on screen, so it essentially runs in the background. This performs our calculation. The only difference I have made in this post is that it overrides the default to Steve and Steve’s relationship state score - BUT only when the current stat is 0 (i.e. the default). This should mean we only override it when it is the first time we run this subroutine. All other times it should be populated with an RO and a value of greater than 0.
The subroutine will then *set your two variables to the name and stat of the highest RO and return to the original code (your scene 20) - at which point the *ifs will fire and play the scene of the newly calculated highest relationship RO.
This allows you to re-use that subroutine over and over (call it in the same way each time) and therefore only need to have the code in the game once.
