Random Variables?

Is there a way to set random variables? For example, what I want to do is code a roulette game, and have it give a random amount of cash in return. Is this possible?

You can use *rand in a bunch of different ways, but it is buggy in that if you refresh the page (click “stats” and the return to the game) you can get a random number every time. It’s a way to “cheat.”

So for roulette, you could do this:

*rand color 1 2
*if color = 1
  *set red true
  *set black false
*if color = 2 
  *set red false
  *set black true
*rand number 1 100

*if red
  Your number is Red ${number}.
*if black
  Your number is Black ${number}.

But keep in mind this would refresh every single time you go to Stats screen. You can get around this by adding in a *page_break right before *if red I think. EDIT: Actually that’s not true, the only way I’ve found to get around it is by switching scenes completely so it doesn’t recalculate *rand every time. It’s very confusing, I think it’s a big headache for everyone, and that’s why they don’t recommend random number generators.

If you get the rand earlier, it stops it. I’m not sure what it needs to ‘lock it’, but I’m sure a *choice works. I thought a *page_break would too, but you say it doesn’t? Hmmmm.

I think I’ve asked this before: @dfabulich Is this just a bug when running it ourselves, or does it continue into published games via iOS and Android? Are there plans to squash it?

  1. Any page of separation between the *rand and where it’s called works (i.e. *choice, *page_break, *finish). Basically, to put it into grossly simple terms, when CS generates a page, it remembers two things, the stats at the start of the page, and where the start of the page is.

When you go to the stats screen then return, it reruns the page from the top. That means rerunning any *rand. So long as *rand does not visibly affect any page on which it is run, no problem, but if it does, well, it redoes the *rand, which affects what the page displays.

  1. It continues to apps and it would be a large change to the way things are handled to get rid of (and it’s easy to work around).

  2. *rand makes games much more difficult to test which is why it’s recommend against (plus on the user end, it’s basically a massive intensive to just try and game by restarting which, best case scenario, is immersion breaking, worst case is frustration inducing).


Okay, that’s interesting. I was playing around with it like that and couldn’t get it to work with page break, and logically I was right along with you, it just baffled me why it kept re-generating.

Or maybe I’m just remembering completely wrong and I was right the first time xD

Good luck with your Random!

I will try the code in a bit, I have to go out but I can try it later.

Thank you all so much!