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?
- 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.
-
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).
-
*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!