Random temp variables

Howdy!

This one is a bit of a doozy.

In my game, you have the option to do certain activities in your downtime. Each of these activities increase the age of your character (since your character is immortal, they can afford to spend a lifetime just focusing on one thing).

I figured it would be silly if your character’s age increased by exactly the same amount each time, so I wanted to increase it by a flat rate (80 years) plus a random amount of time between zero years and forty years. I.E. your character spends between 80-120 years on their task.

I achieved this by running a subroutine for increasing the age of a character. The subroutine goes back to the scene “downtime”, regardless of where you are in the story, as you can also activate this subroutine during other portions of the game, and runs a preset code.

The other thing that makes this a BIT more complicated is that the game checks if you’ve surpassed a certain age. If you are, it runs an “omen” i.e. a quick scene foretelling of dark times ahead. I won’t go into the code for the omens, but it’s basically check the age of the character: if it’s between these two ages and you haven’t already run the omen, then run the omen. Otherwise, nothing happens and the game procedes as normal with nobody the wiser. The omens work really well and I’m pretty proud of that.

So this is what we’ve got so far:

*gosub_scene downtime age_increase

...

*label age_increase

*temp increase 0
*rand increase 0 40

*set age (age + increase)
*set age +80

*gosub_scene omens omens

*return

When I first tested it, everything seemed really great. And for the most part it works perfectly! There’s only one problem. I’ll give you an example.

I select the option to explore the world. I see that my character’s age has increased. I check the stat screen and see that I used to be 200 years old, and now I’m 295. Everything seems great.

So I go back to the description of me exploring the world, and I think, oh man, I actually forgot the age of my character. Silly me. So I open up the stat screen and check again.

Now my age is 301.

Uh oh.

I close the stat screen and open it again. 299.

I close it and open it again. 318.

OH NO.

This wouldn’t be a HUGE issue, but it means you can technically start an omen, open up the statscreen, close it, and then not actually meet the requirements for the omen that you’re currently playing. I haven’t done this yet but it can’t be good.

It’s also a pretty big immersion-breaking issue.

Are there any tips to prevent this?

Notably, one thing which I’m not sure of which I’d like to know even if it’s not a good solution for this particular problem: if you have a temp variable in one scene, and then you go to a subroutine in a completely different scene, does the temp variable persist across both the scene you’re in and the subroutine in another scene? Because that might be a way of counteracting this.

I noticed that the problem DOESN’T persist for this particular bit of code, which randomises how much money you get from an action (in this case, you get between 1800-2200 gold, average 2000).

*temp bonus 0
*rand bonus 0 400

How will you increase your wealth?
*choice
  # I beguile my way into the influence of a merchant's guild.
    *if (charisma >= 40)
      You leverage favours and relationships between some of the most influential people you can find, gaining yourself a tidy sum of money.
      *set wealth (wealth + bonus)
      *set wealth +1800
      *goto_scene downtime
...

Like I mentioned, the amount of money stays the same even if you check your statscreen over and over. I think it’s because the choice moves you to a new page, so the *rand isn’t rerolled.

Thanks for the help! Hope I gave enough information to be useful.

I’ve noticed I have a habit of solving these issues by thinking about them while I write out a post.

The issue is twofold: first, when you go back to a page after checking your stats, it generates the whole page again, which in this case meant rerolling the random temp variable. Second, I was using a temp variable when a regular variable would be more effective.

Also, I figured out that question at the end of my post: the answer is no. Launching a subroutine from another scene ignores any temp variables in the original scene.

So here’s my solution:

In startup.txt:

*create increase 0

At the top of skills.txt, and also at the top of any other scene that requires age increase to be randomised:

*rand increase 0 40

And the new code for the subroutine:

*label age_increase

*set age (age + increase)
*set age +80

*gosub_scene omens omens

*return

It’s not elegant (I’ll have to add *rand increase 0 40 at the beginning of any scene where your age is increased randomly, unfortunately) but it solves this particular issue.

If you have an idea to solve it more elegantly and avoid copy-pasting the same line of code over and over, be my guest. :slight_smile:

Thats an old bug. Easiest way is to create a page_break underneath a short text. Once the game “left” the area with the rand it wont reroll

3 Likes

Yep I discovered this recently, but it’s a relatively easy fix. You need to make sure there’s at least one *page_break between the random roll and when you need to use the stat, otherwise it’ll re-roll every time you move off that page including if you check the stat screen.

If there’s some reason why you absolutely can’t do that (Can’t think of many but there’s a couple if you’re potentially running through that scene more than once and don’t want a random increase each time). You can set a variable that puts the roll behind an *if and gets reset with each age increase.

ie

*if (ageincrease = "yes")
 *temp increase 0
 *rand increase 0 40

 *set age (age + increase)
 *set age +80
 *set ageincrease "no"

Lots of text here. 
Before you need another random roll later in the story, set the age increase back to "yes"
2 Likes

Do you have a rubber duck? That’s the traditional solution. Not that we don’t all benefit from you posting both the problem and the solution to the forums, but explaining the problem to a rubber duck first is always a good idea.

1 Like