Referencing Values

so I have a value that constantly changes, but I’d like to display it so the reader can reference the vale at any time during the stat sheet. I want to make another value that is a copy of that value but only updates to the current value at certain points, and use that as kind of a “The last known value for this” type of thing.

*set showtemp 1 (This turns on the stat showing up in the stat sheet)
*set copyvalue ${value}

and in the sheet we have

*if showtemp = 1
value: ${copyvalue}

this way “value” is constantly changing but you only see “copyvalue” which will update periodically.

3 Likes

You only need the $ in front of the value reference in curly brackets when you want to print it and you only want to put the variable name inside curly brackets if it’s a reference to another variable.

If you intend to set ‘copyvalue’ to the variable referenced in ‘value’, try something like:
*set copyvalue {value}

If you’re setting variables on the stats sheet though, you need to be aware that they get reverted back to the previous value when you return from that page.

1 Like

Hmm so is there not a way to do what I’m thinking then if it will just get reverted back?

Is there any reason you can’t just display the variable using the variable itself?

Value: ${value}

Seems like an easy solution.

According to @lunawisp displaying that in the stat sheet will just reset it

That only applies to *temp variables that get created in the choicescript_stats.txt file. If you make the variable in the startup.txt file, it won’t get reset when opening the stat screen and can be displayed directly.

I’ll try to show an example using checkpoints which is spread across your story, during which when the story enters the CP, the visible stats get updated.

startup.txt
*create var 5
*create display_var 0
Subroutine update
*label update
*set display_var var
*return
Choicescript_stats.txt
Str: ${display_var}
Updating stats
You've reached a checkpoint.
*gosub update

I’m still not sure why they’d need the second variable. They can just display var directly by writing it as ${var} on the stats screen. Any change made to it will reflect on the stats screen.

Aviator wanted to show a stat that only changes at a certain point in the story.


To do this, you’d need a second variable to hold the unchanging-value of the actual stat.

I guess that makes more sense, but I don’t see why the variable needs to update constantly if the player only sees information from it at a certain point. Why not just update the variable only when the display is meant to change?

It is. In my example, you do the *gosub only when you want to update the visible stat.

I still don’t understand exactly how this requires a second variable but I guess you’re seeing something I’m missing so I’ll just let you handle it haha.

And now I feel bad :<

Um, that’s not what I meant. If you change a variable in choicescript_stats.txt, that change is lost when you exit the stats page and return to the game.

You can create a subroutine to call when you want to update stats or just update them inline whenever you feel like it but, as I understand it, if you call that subroutine from the stats screen or update the variable from within the stats screen, the changes you made to that variable are lost.

You can change variables in the stats screen, and as long as it’s not a temp, changes are preserved. However, changes don’t display immediately unless you reload the scene.

@Aviator467 Were you able to resolve your issue?

2 Likes

I believe so!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.