Relationship Calc Question

Evening, Everyone.

I’ve a question about this:

*label highest_relationship_calc
*set rel_counter +1

*label relationship_calc_loop_start
*if rel_counter <= total_rel
	*if rel[rel_counter] > highest_rel_stat
		*set highest_rel_stat rel[rel_counter]
		*set highest_rel rel_name[rel_counter]
	*set rel_counter + 1
	*goto relationship_calc_loop_start
*return

I got this part to work, which is amazing. I’ve also tweaked it to take care of the romance side of things, as well. But here’s where I’m a bit stumped.

The calculation above works to determine which character has the highest friendship and romance value in a story/game. It doesn’t, however, address the times when there’s a tie. I was wondering how you lovely people work with that bit of code, as I haven’t found it yet.

In the project I’m working on, there are four NPCs that have relationship stats and a possible romance option. If a player/reader happens to get two, or more, of them to be equal in either the friendship points or the romance, what sort of code would I need to address that?

If the players do manage to get equal points for two characters, I would like to have a scene where that’s addressed. Where, instead of one character, both are in the scene. I already have a few scenes in mind that deal with that, but I’m stumped on the coding aspects of it.

As is, I’m getting ready to head out to work.

If anyone has any advice, or codes to share, on this, it would be much appreciated.

Thanks In Advance!

Well, there’s a few ways to handle that.

The easiest would be to just check if there’s multiple characters with a relationship variable above a minimum threshold.

In startup:

*create REL_GOOD_THRESH 20

At the top of the chapter:

*temp rel_present_1 false
*temp rel_present_2 false
*temp rel_present_3 false
*temp rel_present_4 false
...etc
*temp number_of_rels_present 0

Then when you want to set their presence in this scene:

*gosub highest_relationship_calc
*set rel_counter 0

*label relationship_presence_loop_start
*set rel_counter + 1
*if rel_counter <= total_rel
    *if (rel[rel_counter] > REL_GOOD_THRESH)
        *set rel_present[rel_counter] true 
        *set number_of_rels_present + 1
    *goto relationship_presence_loop_start
*return

Writing optional descriptions and dialogues based on a set of boolean values is fairly simple, mechanically, just a combinatorics problem.

You might want to short-circuit this scene if nobody qualifies above the minimum threshold:

*if number_of_rels_present = 0
    *return

Alternately, if you only want a scene with exact ties for first place (recognizing this might be very unlikely to happen, assuming the relationships are fairmath rather than simple integers):

*gosub highest_relationship_calc
*set rel_counter 0

*label relationship_presence_loop_start
*set rel_counter + 1
*if rel_counter <= total_rel
    *if (rel[rel_counter] = highest_rel_stat)
        *set rel_present[rel_counter] true 
        *set number_of_rels_present + 1
    *goto relationship_presence_loop_start
*return

Considering how unlikely that is with fairmath values, I might favor

    *if (rel[rel_counter] >= (highest_rel_stat * .85))

or something similar, instead, so you catch close seconds (and thirds, and fourths…) but not distant ones.

1 Like

When I wrote this bit of code originally I didn’t factor in ties because it depends on exactly what you want to do with them. The below is taking your use case of returning 2 or more characters as possible ROs and passing them both to be present in a scene.

I am making assumptions on what exactly you might want to do here:

In startup
*create is_highest_1 false
*create is_highest_2 false
*create is_highest_3 false
*create is_highest_4 false


*label highest_relationship_calc

*set is_highest_1 false
*set is_highest_2 false
*set is_highest_3 false
*set is_highest_4 false

*set rel_counter +1
 
*label relationship_calc_loop_start
 *if rel_counter <= total_rel
	*if rel[rel_counter] > highest_rel_stat
 		*set highest_rel_stat rel[rel_counter]
 		*set highest_rel rel_name[rel_counter]
 	*set rel_counter + 1
 	*goto relationship_calc_loop_start

*if rel_1 = highest_rel_stat
    *set is_highest_1 true
And so on for 2, 3 and 4

*return

This is a simple way to create a boolean flag for whether each character is equal to the highest stat. You can then use the boolean flag to control which character is in your scene. If 2 or more are set to true, then you can include them all in your scene.

There’s other things you could do here too, but this should be a simple way of you being able to build a scene with the ties.

I see you’re starting the loop by setting the counter to +1, that doesn’t look right unless you’re manually setting it to 0 elsewhere?
The original code had it as a temp that just starts as 1, so you don’t have to worry about it at all

4 Likes

This, here. This actually makes what I have in mind far more entertaining to plot. Once I run the check for anyone over the threshold, or within a certain area, it would be a matter of having a boolean to check which ones are there and which ones won’t be.

I don’t use fairmath, however. There’s something about it that makes my brain freeze. I’ve read a few story files to see how they manage it, but I’m still trying to wrap my head around it. For my own story, I have a “counter system” set up, which has worked well so far.

You’ve provided quite a bit to consider on the romance side of things, which I’ll be taking into consideration as I rework a few parts of the story. I might have misunderstood the loop starting at 0, however.

I shifted it from a temp variable to a fixed variable. I’m not a fan of temps.

On my end, the +1 is the first “relationship/romance” checkmark, which will later be checked to see if certain variables I already have are where I want them. Practically everything I have in my own work is boolean-based.

So, in the Startup scene, the counter is set at 0. Then, in the first scene where either the relationship or the romance comes in, it gets a point added to it. I have a few ideas on how to use that and the relationship and romance counters to create variations.

Am I making it harder than needs be? Undoubtedly.

But not nearly as bad, say, having close to 5k in words within the first set of choices within the story itself (and that set of choices isn’t even finished). It’s a monster, in and of itself. I’m loving the process of writing it, and the ungodly amount of booleans being born into existence because of it, but it keeps my brain active.

Thank you, both of you, for stopping by to respond.

Have a night nice (or morning/afternoon)!

2 Likes