Question about game development. Variables?

So. I am a bit unsure of something, sort of.
Currently, my MC has 4 possible ROS. MC just finished chugging something that they were not supposed to chug, and 1 of the possible ROS has gone to assist.
I am unsure how to…

Each choice has a + or - for the RO being spoken to. Unsure weather or not to set a dedicated variable. Temp, in this case, or go by relationship?
If this is unclear, please tell me and I will atempt to clear it up a bit.

I didn’t quite follow what you are attempting to achieve.

Are you wanting to use a variable to determine which of the ROs goes to assist?
Or is the player choosing who assists and you want to use a variable to record which RO was chosen?

It might be helpful to document the specific behaviour you want the code to achieve.

1 Like

I want the code to choose which RO goes to assist based on relationship. Highest relationship based on MC and RO past interactions.

For tracking the overall relationship (across the game) for each RO I would use a permanent, dedicated variable for each (*create RO1_relationship - or whatever you want to call it).

I think you have this, as you mention that your choices + or - for the RO that is being spoken to. For clarity, I would expect something like this:

You walk over and begin chatting to Steve
*choice
    #Tell him he is hot
        *set Steve_relationship + 1
        Some text

    #Tell him he smells
        *set Steve_relationship - 1
        Some text

Then repeat for each different RO, using their dedicated variable in each case.

So you end up with a number of variables (one for each RO) which contains a value of 0 - X, with the higher number denoting a better relationship. You then want to pick which RO enters into a scene based on those relationships.

This is a straightforward, but not so elegant way to achieve this (I haven’t yet thought of whether there is a more elegant way to do it):

Disclaimer: I have tested this briefly, but can not guarantee it is 100% perfect.
This thread also discusses the issue.

*create Steve_relationship 0
*create Sarah_relationship 0
*create Sam_relationship 0
*create Sean_relationship 0

*create Highest_relationship "Steve"
*create Highest_relationship_stat 0

*set Steve_relationship 5
*set Sarah_relationship 3
*set Sam_relationship 6
*set Sean_relationship 6

*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


*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

Lines 1-14 will sit inside your startup.txt
Lines 16-39 will sit in whichever file you want to calculate who has the highest relationship score and have something occur off the back of it.

Setting the Highest to “Steve” at the beginning is just a default. Essentially the code assumes it is Steve, then tests Sarah against Steve’s scores; if she is higher, then she replaces Steve as the highest. Then we test Sam against the ‘highest’ who is now Sarah. By line 26 you now have a text string stored in ‘Highest_relationship’ that you can compare against, you then use that to filter which scene plays - obviously each seen is tailored to the RO that goes to assist.

The main problem arising here is for a tie, Sam and Sean are both 6, but the code will select Sam (as Sean is not higher and therefore that if statement won’t fire). There are ways to handle draws (something along these lines):

*if Sean_relationship > = Highest_relationship_stat
    Do something to record it is a tie
    
    *if Sean_relationship > Higher_relationship_stat
        set Sean as highest

Also, if you are planning to calcute the highest relationship often during your game, it would be worthwhile wrapping lines 16-26 into a subroutine that will go away and calculate the winner, so that you don’t have to repeat that code everywhere.

7 Likes

At wrisk of sounding slightly silly. Could you give me an example of that?
The subroutine, I mean.

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:

  1. One relationship variable per RO
  2. 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.

3 Likes

Thanks!

Will take me a little to get it all figured out? But that’s what I enjoy about this type of codeing anyway, so… Thanks for the explenation smiley.