13 — Chance: how often out of a hundred
The random number of guide 12 rolls a die, and a die gives all
six faces equally often. Chance is different: you decide how often something
happens. Thirty times out of a hundred is written 30% chance.
Steps
Type this into the writing box:
run it →30% chance say You found a coin in the streetRun it ten times and it happens about three times. Some days not at all. Korean is:
run it →30% 확률로 말해줘 길에서 동전을 주웠습니다To hang several lines on the same chance, write it as a block and close it with
end:
run it →10% chance say The sky darkens. say Rain comes down. endA decimal point is allowed to one place:
run it →12.5% chance say This is a rare thingTwo places are refused when the program is compiled.
12.25%is an error, and it tells you to write something like12.3%instead. It does not quietly round, because a program must never decide something its author did not write.A whole number carries no decimal:
50%is exactly fifty in a hundred. You never need to add.0.A chance can be kept as true or false, so the same result can be used in several places:
run it →rain is a 40% chance if rain say Take an umbrella. else say It is clear today. endrainis decided once, when the program reaches that line, and does not change afterwards. Writing40% chanceon two separate lines draws twice, so the two can disagree. When one decision has to hold everywhere, keep it in a name like this.0%never happens and100%always does. Both are useful while you are still building: turn a line on and off without deleting it.
run it →100% chance say This is only a test
Try it
Use a die and a chance together. The die decides what, the chance decides how often.
set die to random number from 1 to 6
say Here it comes
say die
20% chance say And a second one rolled out with it
run it →A name you have given a value to becomes that value inside a sentence. So if
the second line said You rolled the die, the word die would come out as the
number rather than as the word. To print a word as itself, keep the name out of
the sentence.
What you learned
30% chance …happens thirty times in a hundred. Korean is30% 확률로 ….- Open
30% chanceas a block and close it withendto cover several lines. - One decimal place is allowed; two are refused as an error.
name is a 30% chancedecides once and keeps the answer as true or false.0%is never and100%is always.