Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Changing Variable Value with Random Either Function

So I'm trying to create a game where the game randomly generates the text when you click on the room, AND that text is assigned a value.  So, for example, the player is given the choice of weapons, and they choose to use the sword.  That opens up a new passage called "Sword." 

I want the screen to display a random choice:

<<print either("the sword slices through the air", "you miss with the sword but receive a blow from your opponent", "you stab the sword cleanly through your opponent's arm")>>

BUT

Let's say I also am tracking the player's strength with $strength.  I want the second option (you miss with the sword but receive a blow from your opponent) to subtract a point from $strength with $strength = $strength - 1.  And I want the third option (you stab the sword cleanly through your opponent's arm) to add a point to $strength with $strength = $strength +1.

I then want to display the weapons again (using <<display "weapons">>) to take the player back to the original choice room and allow them to choose again. 

How would I add the variable so depending on the text displayed, the variable's value changes?  Is that possible?  Is there another work-around?

Comments

  • I would use a variable (like $attack) and determine its value randomly, like a dice, every time the page loads. Then, dependent on the results, I would print different messages conditionally using the <<if>> macro.  It's no problem to just add a <<set>> macro to the desired conditional message to change the value of $strenght.
Sign In or Register to comment.