Reading variable changes at the top of the page?

I’m having trouble with a display issue. I made a gosub label that displays all your stats and I want to display it at the top of the screen during certain events. Unfortunately, the content of those events come after. So it’s like this:

*page_break
—> *gosub statsdisplay

—> You attend the gala for the holiday.
—> *if (popularity <= 30)
—> —> And have a good time.
—> —> set charisma + 2
—> *else
—> —> And have a great time.
—> —> *set charisma + 5

I want that “statdisplay” gosub command at the top to know about the change in charisma further down the page. I have many pages changing multiple variables, not just one at a time like this example, so while I could just run the stat change code earlier it would be out of place and messy. Is there anyway to get the gosub command to run after the variable changes but still display at the top of the page?

The only way I can think of is if you do the stat changes before *gosub. Maybe this will help.

*temp result ""
*page_break
*if popularity <= 30
    *set result "good"
    *set charisma +2
*else
    *set result "great"
    *set charisma +5
*gosub statsdisplay
You attend the gala for the holiday. And have a ${result} time.
1 Like

This is a fun one that I’ve spent quite a bit of time on.

In short, you can’t do this natively. ChoiceScript redraws its entire page constantly and doesn’t have any native support for persistent UI elements (like a header or footer).

If you’re only doing this in very select parts of your game, you can emulate templates with *gosub_scene.

For e.g.:

*label top
*comment print our header content
*gosub_scene template_header

*comment print out "story" content
*gosub_scene {content_scene} {content_label}

*comment rinse and repeat
*page_break
*goto top

Your “content scene” might look something like:

*label chapter_1
Bla bla chapter 1 is cool
*choice
    # Go to chapter 2
        *set content_label "chapter_2"
        *return
    # Go to chapter 3
        *set content_label "chapter_3"
        *return

*label chapter_2
You reached chapter 2!
Let's start again…
*set content_label "chapter_1"
*return

*label chapter_3
You reached chapter 3!
Let's start again…
*set content_label "chapter_1"
*return

Note the *returns and how you can change the flow of the story by setting content_label appropriately. Your header template scene should likewise contain content you want to appear in the header and always *return back to the main scene. Eventually you’ll end up with something like this:

Kapture 2023-06-20 at 19.44.53

Which is pretty neat (note how the “header” persists) for isolated use-cases. It’s pretty complicated though, so I probably wouldn’t recommended designing your entire game around it.

2 Likes