Warning: Gross oversimplifications ahead.
Twine formats use a parser to read your code, turn it into something the browser understands, and then having the browser display it. This process is expensive (meaning it takes time for it to happen, even if it feels sort of quick), so the formats get around this by basically reading your code once, when a passage is first rendered, and that's about it.
In Harlowe, you can force a chunk of the page to be rerendered over and over again on a time interval using the (live:) macro, but this is incredibly wasteful, and generally not something you want to do if it is at all possible to avoid. This means your only real option is to force the part of the page you need to update when you need it to update.
The easiest way to go about this is to use the (display:) macro (so we only need to write the code we want updated once), and the (replace:) macro, to actually update our code. We'll also need to use a named hook to allow our (replace:) macro to selectively target a part of the page. For more on all of these and their finer points, please refer to the documentation at https://twine2.neocities.org which is maintained by the author of Harlowe, and is basically the Bible for working with that format. It's also all one document, meaning its easily searchable.
First we need to make a passage to display. We'll call it 'stats' to simplify things, and put what is currently in your header there.
:: stats
Energi: $energy
Stolthet: $pride
Note that this code is written in Twee notation, so the ': :' represents a passage name.
Next, in the header, we need to display the 'stats' passage and we need to place it in a hook.
:: header [header]
|statdisplay>[(display: 'stats')]
I called the hook 'statdisplay', and we can refer to this hook using a '?', so it becomes `?statdisplay' when we need to interact with it. Also note that in Twee notation, passage tags go inside brackets next to the passage name.
Now we'll need to use code like this to rerun the code in our header whenever those stats are updated:
:: some passage
{
(set: $energy to 10)
(set: $pride to 10)
(replace: ?statdisplay)[(display: 'stats')]
}
[[Nu börjar det!->Start]]
I made a few other minor changes:
- Don't use upper-case letters in macro names. It will usually work, but isn't recommended.
- I placed the code in braces ({}), which will eliminate unwanted line breaks in the passage output.
You will need to use this replace code any time you update your stats, which is a bit inconvenient, but it's the easiest and most cost-effective way to achieve what you want.
You can also place that code in a footer-tagged passage, to have it run on each passage, but after your changes are made. If you use any interactive elements like (link:) to update any stats, though, you'll need to add the replace in there, even if it's in the footer.