I understand that
You (either: "walk", "run") to the bus stop.
is a mechanism for generating randomness in text, links, or passages. But I assume that creates a 50/50 chance of walking or running, right? What if I want a 70% chance of walking and a 30% chance of running?
Comments
I'm using real world stats like infant mortality, which are, thankfully, low but important.
If that's the case then maybe it'll be cleanest to have a separate passage for each long string of probabilities and then plug them into the part of the story where they belong via (display:) ? Probability / luck is the key factor in whether a choice is displayable in the twine I'm building right now.
So a more complex example might be formatted like:
Is that right?
...Right?
Your range is off in both examples. If you want percentile, the range would be [1, 100] not [0, 100].
Your first example seems to be trying to compare the result to 0.38%. If that's the case and the .38 isn't a typo, then that won't work as (random:) returns integers (i.e. whole numbers). Other than that, it seems okay.
Your second example is problematic on multiple levels. The syntax of the (else:) macros is incorrect and you're using the wrong macro anyway; at least the first needs to be an (elseif:). You're also not testing against anything in the latter two macros. Finally, your third conditional is unreachable as the preceding conditional will always match the same conditions. It should be something more like the following: (assuming the chances are: low is 35%, middle is 60%, and high is 5%)
I don't understand what you mean by Can you explain that more?
Can you recommend a tutorial or guide on if, elseif, and else macros? They've been giving me trouble in general. There's clearly something about it I'm just not getting. I've been looking at tons of examples ... that never work when I try them. And obviosuly the wiki hasn't been updated for Twine 2...
An (if:)→(elseif:)→(else:) chain is processed in-order. So, if you do something like the following: Then the third macro will never be true because the preceding macro's condition, $roll <= 60, will always yield true for any value which would also make its condition, $roll <= 35, true. So, the only values which will make it down the chain to the third macro are those that are greater than 60, which will never drive its condition true.
Have you tried the Harlowe docs?
Beyond that, it sounds like you need to review some beginners programming guides. I'd suggest asking
the Oracle of DelphiGoogle.I'll click around! A lot of what I've seen doesn't *quite* work as epxected in Twine. Doing a lot of trial by error. But I'm learing a ton really fast, which is really exciting!
For some reason, even though $oddsGEN is getting randomly assigned values as it should, $GEN is being set to 5 no matter what. Earlier I had a slightly different syntax in place (I forget what), I was only getting 1s and 2s, even though other $oddGEN values were populating.
Can anyone tell me what I'm doing wrong?
2. The (else:) macro does not take a condition, it always succeeds. So, the last macro in the chain either needs to be an (elseif:) or you should remove the condition from the (else:).
3. You're skipping parts of your range, which I doubt you intended, because you're doing things like < 14 then > 14, which skips 14.
Your code is also highly redundant, it would be better like so: (added extra whitespace and comments for clarity) I don't know if I hit the ranges you wanted there, but your code wasn't doing that anyway, so….
A couple of issues with your example:
a. The (else:) macro ignores any condition parameters you pass to it so things like (else: $oddsGEN is 100) should be just (else:)
b. Because of the way you are coding your ranges the variable $GEN will be set to 5 whenever $oddsGEN equals the values of 14, 29, 64, 99 or 100.
c. You don't use the is keyword when using symbols like >, <, >=, <=
d. Because you are using (else-if:) and (else:) macros you do not need to include a test for the lower edge of each of your ranges.
e. It is a good idea to insert a single space character between the colon at the end of a macro name and the parameter(s) of that macro.
Try the following:
First would hold the cumulative threshold values - search through it and return the index into the array of the first value that greater than the generated value.
Second would be a set of text messages and links for each index value...