Hello, before I post my question I'd just like to say I've been a long time lurker on the Twine Forum and want to give my thank-you's to all the brilliant people here. So this is my first post.
Edit: I'm Using The Sugarcube Header
So, I have certain numerical statistics in my story, mainly stuff like $Player.Health and $Player.Hunger and so on. I don't know if there would be a more "efficient" way of going about this, but I've been using 0-100 as most stats "min/max". That is to say, my PassageDone passage in Sugarcube has a lot of stuff like this in it -
<<if $Player.Health gt 100>>
<<set $Player.Health = 100>>
<<endif>>
<<if $Player.Health lt 0>>
<<set $Player.Health = 0; $Player.Dead = true>>
<<endif>>
And when I say a lot, I mean lines and lines...
The good thing is, it works. But I can't help but feeling there must be a much more quick and efficient way to go about this, to prevent information overload when viewing the code, and potentially save some time in the future.
I've thought about using Sugarcube's built-in Widget system in some way, but just cant wrap my mind around how to go about doing so.
Thanks for reading this, and I'll be waiting for some advice. Your input wont be ignored!
Comments
To put it all together in a widget, you could do something like this: Usage:
Math.random()
). While most browser implementations aren't terrible, they also don't allow any control over the seed (every time the browser reloads the page, the PRNG gets a new seed). This has implications for games that use the PRNG for various things. In particular, going back within the history, even if the player didn't change anything, could alter state.For those games that need a seedable PRNG, to ensure that state based on the PRNG doesn't start shifting on the player just for moving around the history, SugarCube includes a seedable PRNG. Using
History.initPRNG()
initializes that PRNG and integrates its state into the game state, so for the life of that instance of the game the same seed will be used (and, since its state is stored as a part of the general game state, it also persists over saves).