Assistance in understanding the relationship_calc file

I’m having trouble with…

The error I’m getting is:…

My code looks like this:

Example
*commend
    Indent
```So. As it stand now, I know a little about the relationship counter, but several people, thanks by the way, have been telling me to actually get to understand the thing, which is why I'm creating this.
I'm going to put in my current relationship_counter, and put in little notes where I do understand things and do not. Would you, as in the forum community, be able to help me understand this so I don't run into, at least as many, issues with this in the future?


*label highest_relationship
*set relationship_counter 1
This is the actually tracker, as in it’s a bit like a switch, or a needle, where in it points to relationship that’s currently being checked, such as in *if highest_relationship, correct?

*label relationship_calc_loop
*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}
So, the *set relationship, and *set relationship_name are pretty streight forward, with the first being the initial variable, and the second setting exactly what said variable is. Correct?
*if Relationship_counter <= Total_relationships
*if relationship[Relationship_counter] > Highest_relationship_stat
*set Highest_relationship_stat relationship[Relationship_counter]
*set highest_relationship relationship_name[Relationship_counter]
*set Relationship_counter + 1
*goto relationship_calc_loop
*return

Yeah, I have no idea what any of the stuff between this and my last comment is, apart from the *goto, command is. I think it’s to set it all up, but without actually understanding what the individual parts do, I can’t actually understand it better than that. shrug?


So, yeah. Also, if I wasn't actually supposed to do that, please tell me so I can work out something better next time.
Anyway, I hope that you all have a good rest of your day!

You did not say what the error message was. Also your post was a little confusing to follow. Going forward I recommend only putting code under the preformatted text as followed.

*label relationship_calc_loop
*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

This will make it easier to read when we are looking at the code as written or just talking about it. Speaking of this code you are missing an underscore for relationship_5. This might cause an error. You are also missing a quotation for relationship_name_5. On top of that your quotations might be too curly for the system. You might need simplified quotation marks. Like this: "

It is hard to tell your indenting formatting for the rest of your code to try and figure out if anything is wrong. It would be pure guessing for what is wrong without seeing those indentions and without knowing the error message you are getting.

1 Like

This is maybe going to be long. Also this code is kinda… not amazing, I can see multiple problems that could crop up immediately.

*label relationship_calc_loop
*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}
So, the *set relationship, and *set relationship_name are pretty streight forward, with the first being the initial variable, and the second setting exactly what said variable is. Correct?

*return

*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

This section is building two arrays (more info here explaining what an array is Array Explained In 1 Minute - YouTube and here explaining how it works in choicescript Arrays | ChoiceScript Wiki | Fandom). At each index of the array, the array “relationship” holds the numerical value of that relationship, while the array “relationship_name” holds the name of the person that relationship corresponds to.

*if Relationship_counter <= Total_relationships
  *if relationship[Relationship_counter] > Highest_relationship_stat
    *set Highest_relationship_stat relationship[Relationship_counter]
    *set highest_relationship relationship_name[Relationship_counter]
  *set Relationship_counter + 1
  *goto relationship_calc_loop

This section goes the arrays to look at each relationship value. Basically it has a variable “Highest_relationship_stat” which is tracking the highest relationship stat seen so far and “highest_relationship” which is tracking the name of the person that has the relationship value in Highest_relationship_stat. For each relationship, its checking if its higher than the one currently stored. If it is, than that relationship number and person name become the new highest_relationship_stat and highest_relationship.

Once its checked everything, it does the

*return
The Long Explanation - Line by Line

Here I’m going to go line by line with hypothetical values
Going into this, lets assume
t_relationship: 60
t_name: Taylor
l_relationship: 50
l_name: Lana
n_relationship: 70
n_name: Nathan
d_relationship: 65
d_name: Dylan
v_relationship: 80
v_name: Vera

Total_relationships: 5

Also, going into this, idk, start with:
Highest_relationship_stat: 0
highest_relationship: noname

*set relationship_counter 1

This gives you a variable
relationship_counter: 1

*label relationship_calc_loop

This creates a marker “relationship_calc_loop” that the code will direct to go to at a later point.

*set relationship_1 t_relationship

This is an array “relationship”
relationship[1]: t_relationship
with the example values given,
relationship[1]: 60

*set relationship_name_1 “${t_name}”

This is a second array “relationship_name” where
relationship_name[1]: t_name
with the example values given, you have
relationship_name[1]: Taylor

*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”

Similar principle. After running this, with the example values given you would now have:
relationship[1]: 60
relationship[2]: 50

relationship_name[1]: Taylor
relationship_name[2]: Lana

you’ll notice that these values correspond to the relationship value and names of t and l.

*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

Same concept for this section, by the end of it, you’ll have:
relationship[1]: 60
relationship[2]: 50
relationship[3]: 70
relationship[4]: 65
relationship[5]: 80

relationship_name[1]: Taylor
relationship_name[2]: Lana
relationship_name[3]: Nathan
relationship_name[4]: Dylan
relationship_name[5]: Vera
each index of the array represents a person. t is at position 1, so if you check the two arrays, the relationship with t is 60 and t’s name is Taylor. d is in position 4, the relationship with d is 65 and d’s name is Dylan.

Here is the more involved part:

*if Relationship_counter <= Total_relationships

This checks if your relationship counter is either smaller than, or equal to the number of relationships. If it is, it runs what is nested underneath, if not, skips everything nested and goes to the return.

At this point, “relationship_counter” is 1 and “Total_relationships” is 5. Since 1 is less than or equal to 5, the indented code underneath runs.

*if relationship[Relationship_counter] > Highest_relationship_stat

This now checks the relationship. Its looking if the value in the "relationship_counter"th position of “relationship” is greater than “Highest_relationship_stat”. If it is, it runs the code indented beneath it. If it is smaller than or equal to “Highest_relationship_stat” the code goes to *set Relationship_counter.

In our example, Highest_relationship_stat is 0. relationship_counter is 1 so its checking relationship at the 1st postion. relationship[1] is 60. 60 is greater than 0 so the if statement is true and the code indented under it runs.

*set Highest_relationship_stat relationship[Relationship_counter]
*set highest_relationship relationship_name[Relationship_counter]

Now this runs. It now sets “Highest_relationship_stat” to whatever value was stored in the position of “relationship” you were currently looking at. “highest_relationship” is set to the corresponding name.

In our example, going into this Highest_relationship_stat is set to the value in relationship[1], Highest_relationship_stat is now 60. highest_relationship is set to the value at relationship_name[1], highest_relationship is now “Taylor”.

Ending of this:
Highest_relationship_stat: 60
highest_relationship: Taylor

*set Relationship_counter + 1

This adds 1 to the variable “Relationship_counter”.

In our example, Relationship_counter was 1. After adding 1 to it, Relationship_counter is now 2, indicating that next time we will be looking at the 2nd position in the arrays.

*goto relationship_calc_loop

This is telling the computer to go allllll the way back to the *label relationship_calc_loop earlier in the code.

*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

runs again, no different from before, just setting the values in the arrays again.

*if Relationship_counter <= Total_relationships

Checks this again. In the current example, Relationship_counter is still less than total relationships, so everything indented runs.

*if relationship[Relationship_counter] > Highest_relationship_stat

In our example, relationship[2] is 50 and Highest_relationship_stat is 60. 50 is LESS THAN 60 so the code under this does not run.

*set Relationship_counter + 1
*goto relationship_calc_loop

Same as before, goes back to *label relationship_calc_loop but this time, Relationship_counter is 3, meaning we’re looking at the 3rd position.

*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

Does this again

*if Relationship_counter <= Total_relationships

Is 3 less than 5? Yes? Runs indented code

*if relationship[Relationship_counter] > Highest_relationship_stat

relationship[3] is 70, Highest_relationship_stat is 60. 70 greater than 60? Yes? Run indented code.

*set Highest_relationship_stat relationship[Relationship_counter]
*set highest_relationship relationship_name[Relationship_counter]

After running,
Highest_relationship_stat: 70
highest_relationship: Nathan

*set Relationship_counter + 1
*goto relationship_calc_loop

Do it again but relationship counter is now 4, look at the 4th position.

*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

This runs again

*if Relationship_counter <= Total_relationships

Is 4 less than or equal to 5? Yes? Do the stuff indented.

*if relationship[Relationship_counter] > Highest_relationship_stat

relationship[4] is 65, Highest_relationship_stat is 70. 65 < 70? No? Skip indented.

*set Relationship_counter + 1
*goto relationship_calc_loop

Do it again but Relationship_counter is 5, look at 5th position.

*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

This again

*if Relationship_counter <= Total_relationships

Is 5 less than or equal to 5? Equal to? Run indented.

*if relationship[Relationship_counter] > Highest_relationship_stat

relationship[5] is 80, Highest_relationship_stat is 70. 80 > 70? Yes? Run indented.

*set Highest_relationship_stat relationship[Relationship_counter]
*set highest_relationship relationship_name[Relationship_counter]

After running this,
Highest_relationship_stat: 80
highest_relationship: Dylan

*set Relationship_counter + 1
*goto relationship_calc_loop

Do it again but relationship_counter is 6

*set relationship_1 t_relationship
*set relationship_name_1 “${t_name}”
*set relationship_2 l_relationship
*set relationship_name_2 “${l_name}”
*set relationship_3 n_relationship
*set relationship_name_3 “${n_name}”
*set relationship_4 d_relationship
*set relationship_name_4 “${d_name}”
*set relationship 5 v_relationship
*set relationship_name_5 "${v_name}

This again

*if Relationship_counter <= Total_relationships

Relationship_counter is 6, Total_relationships is 5. Is 6 greater than or equal to 5? No? Skip intented and go to the *return

*return

code is over
By the end of this
Highest_relationship_stat is 80
highest_relationship is "Dylan.

So, the original error had to do with the fact that I had a

*if (highest_relationship) ="x"
  *goto Y

I had 4 different *if’s, but even when the relationship of 1 was set higher, it would still always go to one particular one, and am trying to figure out why. So, I decided that I would try to understand exactly what the relationship tracker did as best as I could to try and help with that.
Also, would it help if I put my comments in

*comment

before I put them in, or just put them below the choicescript commands instead of directly after what I wanted to comment about, like I did earlier?

Also, here are my created relationship variables, just in case I missed something or something to that affect:

*comment highest_relationship_variables
*create total_relationships 5
*create highest_relationship_stat 0
*create highest_relationship ""
*create relationship_counter 1
*create relationship_1 0
*create relationship_name_1 " "
*create relationship_2 0
*create relationship_name_2 " "
*create relationship_3 0
*create relationship_name_3 " "
*create relationship_4 0
*create relationship_name_4 " "
*create relationship_5 0
*create relationship_5_name ""

Haven’t tested, just assumptions based on the info across a few of your posts.

Ok so like, there are multiple problems.

First off, after running the code you gave for relationship calc, highest_relationship will be "${x_name}" where x is the person you have the highest relationship with.

Visual

So I think you would need to do something like

*label reassurance
*if (highest_relationship) = "${t_name}"
	*goto t_reassure
*elseif (highest_relationship) = "${l_name}"
	*goto l_reassure
*elseif (highest_relationship) = "${n_name}"
	*goto n_reassure
*elseif (highest_relationship) = "${d_name}"
	*goto d_reassure

SECONDLY, make sure that the l_name, t_name etc are set to distinct values. If l_name and t_name are the same value, it will mess up the if statements.

1 Like

I just ran it, with the alterations you suggested and it is still doing the same time.
Do you have a recommendation as how to print out the highest_relationship variable, so I can check if it’s something in the relationship tracker itself, or something in the transfer from the tracker to the game?

just use ${highest_relationship}, also make sure you’ve set the names on everyone, if every name variable is " ", its gonna cause problems

Hi, I don’t know if you’ve found a solution to this yet. When I tried testing out the code, the issue I had was with the relationship_counter:

*if relationship_counter <= total_relationships
    *if relationship[relationship_counter] > highest_relationship_stat
        *set highest_relationship_stat relationship[relationship_counter]
    *set highest_relationship relationship_name[relationship_counter]
    *set relationship_counter + 1
    *gosub relationship_calc_loop

So, instead of looking at all the relationships, it just looked at the number of relationships (i.e., the relationship counter itself) that you had. I don’t know if that’s what you’re experiencing, but if it always defaults to the first one, and the relationship_counter is 1 when you test it - there’s the source of the error.

I’m not very familiar with arrays, so I’m not sure how to fix it. However, if you want to try a different approach, you can see how this works for you:

*label relationship_calc_loop
*set highest_relationship_stat 0
*if (t_relationship > highest_relationship_stat)
    *set highest_relationship_stat t_relationship
    *set highest_relationship "${t_name}"
*if (l_relationship > highest_relationship_stat)
    *set highest_relationship_stat l_relationship
    *set highest_relationship "${l_name}"
*if (n_relationship > highest_relationship_stat)
    *set highest_relationship_stat n_relationship
    *set highest_relationship "${n_name}"
*if (d_relationship > highest_relationship_stat)
    *set highest_relationship_stat d_relationship
    *set highest_relationship "{d_name}"
*if (v_relationship > highest_relationship_stat)
    *set highest_relationship_stat v_relationship
    *set highest_relationship "${v_name}"
*return

I took out the relationship_counter because I’m not sure if it’s needed. Do you need to keep track of whether the player has met/has a relationship with the RO before adding them into the calculation? I can see how that would be necessary (especially if a relationship loses points), but a boolean (true/false check for each individual RO) might work better, depending on how the ROs are introduced.

1 Like

Not the OP, but, relationship_counter is acting as the counter for the loop.

The first bit where all the variables are set is creating an array and

*if relationship_counter <= total_relationships
    *if relationship[relationship_counter] > highest_relationship_stat
        *set highest_relationship_stat relationship[relationship_counter]
        *set highest_relationship relationship_name[relationship_counter]
    *set relationship_counter + 1
    *gosub relationship_calc_loop

is looping through the arrays checking
basically the intention is

relationship_counter = 1
while (relationship_counter < total_relationships)
    if (relationship[relationship_counter] > highest_relationship_stat)
        highest_relationship_stat = relationship[relationship_counter]
        highest_relationship relationship_name[relationship_counter]
    relationship_counter += 1;

No idea if its working correctly lmao, and i prefer your method with the if statements since there really isn’t a need for the arrays and loops and stuff but… yeah. It should work in theory but without seeing the rest of everything else… its hard to tell if the problem is with this script or a mistake was made elsewhere.

1 Like

Okay, thanks for the explanation. :+1: I didn’t quite get that it’s supposed to be a counter for the loop itself.

In that case, I think the way to make it work is to reset the relationship_counter to 1 and highest_relationship_stat to 0 whenever you want to do a check, and then be sure to loop through 5 times to check each individual relationship. Would help to put it all into a subroutine, like so:

*label Checking_all_relationships
*set relationship_counter 1
*set highest_relationship_stat 0
*gosub relationship_calculater
*gosub relationship_calculater
*gosub relationship_calculater
*gosub relationship_calculater
*gosub relationship_calculater
*return

I’d also suggest putting the *gosub relationship_calc_loop at the beginning of the “relationship_calculator”, as it produces a weird error for the first loop if it’s at the end:

*label relationship_calculater
*if (relationship_counter <= total_relationships)
    *gosub relationship_calc_loop
    *if (relationship[relationship_counter] > highest_relationship_stat)
        *set highest_relationship_stat relationship[relationship_counter]
        *set highest_relationship relationship_name[relationship_counter]
    *set relationship_counter +1
    *return

@ArchivistAlpha096 Let me know if this helps!

Because relationships can loose points, yes, but I’ll run your code and see if that fixes things. Also, thanks for the suggestion about the relationship counter, as I did not think of that.

1 Like

When I run the code with the

${highest_relationship}

it comes up as just blank. It says the relationships fine enough, but not the highest_relationship, if that helps any.
Is it just me, or is this very confusing?

1 Like

It could be because you don’t have the t_name, l_name variables set to anything aside from " " so its just outputting a space

This would also cause the problem mentioned in your if statements. If every x_name variable is equal to " " then the first if statement will always resolve.

1 Like

Could be. Not sure how to change that, as I thought I had the names set, such as:

*set relationship_1 t_relationship
*set relationship_1_name "${t_relationship}"

but, I guess that isn’t correct?
slightly confused face

Not sure if you’ve solved the issue or not, but from what I underatand you are trying to find an elegant solution for finding what the highest relationship is from a set of values and then getting the name of the character coresponding to that relationship?

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.

More or less, yes.
Right now I have a work-around, although I would rather just be able to do something like:

*if (t_relationship =highest_relationship)
  *goto X

Right now, I have to do:

*if ((t_relationship >l_relationship) and (t_relationship >${n_relationship)) and (t_relationship >d_relationship))

It works, but it’s a pain to write all the time, which is why I’m still searching for firstly, why the

${highest_relationship}

still says blank when I enter it into the code. If you need, I can re-post my highest_calc so someone can look at it and find the disconnect?

Sure you can post it and I can have a look. Is it different from the one in the 1st post?

Is there any way you could link the entire project? It would make it easier to figure out if the problem is with highest_calc or somewhere else.