0 votes
by (170 points)

A beginner here. How can I add a variable to Player's choice without adding a separate passage for it? 

Example:

Let's say I want the Player to create a character for an adventure game in 3 passages. I would start with choosing class, then choosing race and then a summary.

Class passage:

Choose your class:
[[A mage|race]]
[[A rogue|race]]
[[A warrior|race]]

Now I want the Player to choose a race in the second passage (race),

Choose your race:
[[A human|summary]]
[[A dwarf|summary]]
[[An elf|summary]]

and then in the last passage (summary) I want to inform him about his character:

Congratulations, you're a $race $class.

I know that to set a variable I need to use

<<set $class = "mage">>

 I do not know however how to set $class and $race depending in Player's choices without adding an additional passage.

Thanks in advance!

PS

I've looked through tutorials, but haven't found answer to my question.

1 Answer

+2 votes
by (62.7k points)

You can use 

  1. A "setter" link, or
  2. The <<link>> macro in combination with a <<set>> macro. 

Examples: 

—> setter link (recommended)
[[A mage|race][$class to "mage"]]

—> link and set macros (if you have additional, non "set" code as well 
<<link [[A mage|race]]>>
    <<set $class to "mage">>
<</link>>

Further reading: 

Link markup and setters: http://www.motoslave.net/sugarcube/2/docs/markup.html#links

The <<link>> macro: http://www.motoslave.net/sugarcube/2/docs/macros.html#macros-link

by (170 points)
This helps A LOT. Many thanks, Chapel!
...