Where do I put this?

Hello everyone! I was wondering where I should put this subroutine so that the program would constantly refer back to it whenever the relationship of a person (such as Jordan) is changed. I’m not getting any errors where it is currently - after the *create - but I’m almost certain that it isn’t active either.

*if KnowJordan and (JordanRelationship >=47)
     *set Jordan 1
     *finish
*elseif KnowJordan and ((JordanRelationship >=30) and (JordanRelationship <47))
     *set Jordan 2
     *finish
*elseif KnowJordan and (JordanRelationship <30)
     *set Jordan 3
     *finish
*else
     *set Jordan 0
     *finish

This is an example for one of my characters. 0 means that it is hidden, 1 makes it show in my ‘Friend’ section of stats, 2 in ‘Neutrals’ and 3 in ‘Enemies’. Although the code is likely extremely over-complicated, I think it would work, I just don’t know where to put it so that it can. :slight_smile: Thanks for the help!

Will that variable be used for other purposes? Or will it only ever be checked on the stats screen, to determine what part of the stats screen displays the relationship in question?

If that variable’s only ever used on the stats screen, you might as well put this code there. Then you won’t need any extra code. Just put the code that sets it high enough up in the choicescript_stats.txt file that it runs before the variable is checked.

If you might use the variable elsewhere in the game, then it would be helpful to run the subroutine with a *gosub or *gosub_scene command.

4 Likes

Create a file for this, such as something called relationships.txt.

Then use a *gosub_scene relationships command whenever you alter the JordanRelationship variable.

There are ways to improve on it, such as calling just the gosub and the amount you wanna change on the same command and then it will do all that check for the 0, 1, 2 and 3 automatically.

If you’re interested, let me know and I’ll explain.

4 Likes

You can put it wherever you need it! Since these are subroutines to set relationship variables, I imagine you’ll be calling them across scenes, which means you’ll probably want to use *gosub_scene. That function allows you to call a routine across scenes. I personally would make a scene specifically for your subroutines.

For example, if you have a subroutine scene named “relationships” and have Jordan’s function under the label “jordan”, you could call it from anywhere like:

*gosub_scene relationships jordan

Although, you will need to call the routine when you want it to run. It won’t be constantly running in the background. More information on the ChoiceScript Wiki:

2 Likes

This can be changed by choices later on. Where would I put *gosub? Would I have to put it after every change in relationship? (I’d completely forgotten about gosub’s by the way thanks for reminding me!)

I think I get it, the gosub_scenes would work. Could I put all the character subroutines in there or do one for each?

Minnow was asking if this status will ever be used or displayed somewhere else, because otherwise you can just leave all of this code inside choicescript_stats.txt since that will be the only place where it would be used and as such the only place where you would need to update the status.

1 Like

Oh, I think it’ll be used in stats and other scenes as well as it would affect the choices you can make.

You could do all relationships in one gosub_scene file

However, while it is extra files, it might well make it easier for you - when coding - to have a separate file for each character

(unless there is a relationship matrix … where non-MC characters can also have relationships with each other … then 1 file might be the only way)

As ever, kinda depends on exactly what you’re going to do with it :slight_smile:

1 Like

I’d like to do a relationship matrix but I’d have to figure out how to do that as I go as I have no clue how it would be coded. I think I’ll try one gosub_scene file first. How is making separate files easier?

You don’t have to include a (possibly) complex IF statement to work out which relationship you are dealing with, when you run the gosub.

If you want to change the relationship to “Mary” you run MAry’s gosub … If “Jane” then Jane’s.

It doesn’t really matter - Just makes it easier to follow/deal with (for me, at least).

Relationship Matrix: Yes, that is harder … So I’d suggest trying out this simpler version and expand your code from there

1 Like

Probably a good idea. I’m going to have a good at the *gosub_scene now :slight_smile:

Here is a simple way to change stat and do this check in one go. I added it for Jordan and added a second character called Jenny (just to show how you can do this for another character, just change Jennys variables to whatever is the character variables.

Create a relationships.txt file and put the code inside it.

The value you want to change the relationship is received as a parameter when the *gosub is called, it will then modify the relationship stat by that amount and set the friendship status accordingly.

*comment ========================|JORDAN|========================
*label jordan_relationship
*params change_amount

*set JordanRelationship + change_amount

*if KnowJordan and (JordanRelationship >= 47)
  *set Jordan 1
*elseif KnowJordan and ((JordanRelationship >= 30) and (JordanRelationship < 47))
  *set Jordan 2
*elseif KnowJordan and (JordanRelationship < 30)
  *set Jordan 3
*else
  *set Jordan 0

*return
*comment ========================|JENNY|========================
*label jenny_relationship
*params change_amount

*set JennyRelationship + change_amount

*if KnowJenny and (JennyRelationship >= 47)
  *set Jenny 1
*elseif KnowJenny and ((JennyRelationship >= 30) and (JennyRelationship < 47))
  *set Jenny 2
*elseif KnowJenny and (JennyRelationship < 30)
  *set Jenny 3
*else
  *set Jenny 0

*return

To utilize this gosub, simply use this whenever you want to change someones relationship:

*gosub_scene relationships CHARACTERNAME_relationship AMOUNT_TO_CHANGE

As in:

*gosub_scene relationships jordan_relationship "10"

This amount should be passed as string (between quotes) so that it works with negative numbers if you want to decrease relationship (as in “-10”).

There is a way to simplify that to work for all characters, but it would require you to make the *gosub call a little longer everytime you used it, I can do that one if you want.

4 Likes

It would be amazing for it to work for all characters, so yes please! That’s really smart for the code by the way ^

Sorry to bother you for something else as well, but I was trying out the separate *gosub_scene, and for some reason it no longer sees my first scene (prologue), saying that it no longer exists although I didn’t change it…

Here is the new code for relationships.txt then, this will work for any companion:

This time we are receiving all variables that will work on here when the gosub is called. Through them, the code will know which variables to change.

*label change
*params friendship_status_var know_var relationship_var change_amount

*set {relationship_var} + change_amount

*if ({know_var})
  *if ({relationship_var} >= 47)
    *set {friendship_status_var} 1
  *elseif (({relationship_var} >= 30) and ({relationship_var} < 47))
    *set {friendship_status_var} 2
  *else
    *set {friendship_status_var} 3
*else
  *set {friendship_status_var} 0

*return

To use the gosub everytime the relationship is to be changed:

*gosub_scene relationships change FRIENDSHIP_STATUS_VAR KNOW_VAR RELATIONSHIP_VAR AMOUNT_TO_CHANGE

As in, with the current variables you’re using:

*gosub_scene relationships change Jordan KnowJordan JordanRelationship "10"

Some testing might be needed as I haven’t tested things out right now, just basing all of this on some stuff I did a while ago for a friend.


What exactly did you change? And is the error when you’re calling the *gosub_scene? Is the error not for the relationships.txt file instead of the prologue?

4 Likes

That’s great thanks so much! I’ll try it out right away! :smiley: Well when I can.

The error comes up the moment I click run. It stays blank and just says my first scene doesn’t exist.
Screen Shot 2020-01-05 at Sun, 5 Jan 9.34.31
The only changes I’ve made was deleting the useless if statements I had in the startup and creating the new relationship.txt with a *gosub_scene link to it later in the prologue scene.

Do you have prologue on the *scene_list and a file called prologue.txt?

Yep I have a .txt for it and I made sure it’s in the scene_list too.

Have you saved “All Files”? (As in, saved the “Project”)

I have (or at least none of the save symbols are red).