0 votes
by (490 points)
hi! I'm throwing together a Fallen London-inspired Interactive Fiction piece for a project I'm doing, and I'm just hashing out the basic interface/mechanics of it. The main thing that's got me stuck is how certain events in the game unfold - the player has a set of qualities, or stats, that can go from 1-10 based on how they allocate their points. What I want to do is make options available to them that have different probabilities of occuring based on how high that quality is.

For example, a certain option might have a 60% chance of success given that a player's 'Spooky' quality was at 6, and if they manage to 'suceed' in the option, then they'll be directed to a particular page - if not, another.

I just have no idea how to do a probability-based event system, basically! help would be greatly appreciated.


(edit: hit publish too early, whoops)

1 Answer

0 votes
by (44.7k points)
selected by
Best answer

The easiest way to do this is by using the <<link>> and <<goto>> macros with the random() function like this:

<<link "Attempt the 'spooky' maneuver">>
	<<if $Spooky >= random(1, 10)>>
		<<goto "Spooky Success Passage">>
		<<goto "Spooky Failure Passage">>

So that will display a link which says, "Attempt the 'spooky' maneuver".  If the user clicks on that link it will check the value of the $Spooky variable (which should be an integer) against a random value from 1 to 10.  If $Spooky is greater than or equal to the random value, then it will take you to the passage named "Spooky Success Passage", otherwise it will take you to the "Spooky Failure Passage".

This means that if $Spooky is zero or less, it will always fail in the above code, and if it's ten or more, it will always succeed.  So this will give you that 60% chance success rate if $Spooky is set to 6.

A Word of Caution: The <<goto>> macro does not prevent it from executing lines of code which follow that macro, so make sure that if you use that macro that there isn't any other code after that which you don't want triggered (like another <<goto>> or whatever).

Hope that helps!  :-)

by (490 points)
Works perfectly, thank you!