User Tools

Site Tools


harlowe:set

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

harlowe:set [2017/06/20 02:27]
l created
harlowe:set [2017/10/09 20:39]
Line 1: Line 1:
-**(set: //​...[[harlowe:​VariableToValue|variabletovalue]]//​) -> //​Instant//​** 
  
-Harlowe'​s version of the "​set"​ macro, common to most Twine story formats. 
- 
-=== Example usage: === 
- 
-  * ''​%%(set:​ $battlecry to "Save a " + $favouritefood + " for me!"​)%%''​ sets a variable called $battlecry. 
-  * ''​%%(set:​ _dist to $altitude - $enemyAltitude)%%''​ sets a temp variable called _dist. 
- 
-=== Rationale: === 
- 
-In Harlowe, there are two kinds of variables. Normal variables, whose names begin with ''​%%$%%'',​ persist between passages, 
-and should be used to store data that will be needed throughout the entire game. Temp variables, 
-whose names begin with ''​%%_%%'',​ only exist inside the hook or passage that they'​re first (set:), and 
-are forgotten after the hook or passage ends. You should use temp variables if you're writing passage 
-code that mustn'​t accidentally affect any other passages'​ variables (by using (set:) on a variable name 
-that someone else was using for something different). This can be essential in collaborative work 
-with other authors working on the same story independently,​ or when writing code to be used in multiple stories. 
- 
-Variables have many purposes in Harlowe: keeping track of what the player has accomplished,​ 
-managing some other state of the story, storing hook styles and [[harlowe:​changer|changer]],​ and 
-other such things. You can display variables by putting them in passage text, 
-attach them to hooks, and create and change them using the (set:) and [[harlowe:​put|(put:​)]] macros. 
- 
-=== Details: === 
- 
-In its basic form, a variable is created or changed using ''​%%(set:​%%''​ variable ''​%%to%%''​ value ''​%%)%%''​. 
-You can also set multiple variables in a single (set:) by separating each VariableToValue 
-with commas: ''​%%(set:​ $weapon to '​hands',​ $armour to '​naked'​)%%'',​ etc. 
- 
-You can also use ''​%%it%%''​ in expressions on the right-side of ''​%%to%%''​. Much as in other 
-expressions,​ it's a shorthand for what's on the left side: ''​%%(set:​ $vases to it + 1)%%''​ 
-is a shorthand for ''​%%(set:​ $vases to $vases + 1)%%''​. 
- 
-If the destination isn't something that can be changed - for instance, if you're trying to set a 
-bare value to another value, like ''​%%(set:​ true to 2)%%''​ - then an error will be printed. This includes 
-modifying [[harlowe:​array|array]] - ''​%%(set:​ (a:​2,​3)'​s 1st to 1)%%''​ is also an error. 
- 
-=== See also: === 
- 
-[[harlowe:​push|(push:​)]],​ [[harlowe:​move|(move:​)]] 
harlowe/set.txt ยท Last modified: 2017/10/09 20:39 (external edit)