Can't update variable with an "if" statement

Twine version is 2.7.1.0. Very new so sorry if this is a simple question. I am trying to update a variable when the player takes an item to track an inventory system but I’m getting the error that “A (set:) operation can’t have changers like (if:) attached.
Changers placed just before hooks, links and commands will attempt to attach, but in this case it didn’t work.”

my code looks like:

(set:$HandSpace to 2) ```

and then:

``` [Take the candle (if:$Handspace > 0) (set:$Candles to it + 1) (set:$HandSpace to it - 1)] ```

Obviously there's some dialogue and other parts etc but it seems to just be the variables that aren't working and I'm not sure why this operation wouldn't be possible.

There might be a more idiomatic Harlowe way, but this worked for me:

Source
:: StoryTitle
Inv


:: StoryData
{
  "ifid": "8BB6EFEF-DE98-4459-8DF3-B723153063B2",
  "format": "Harlowe",
  "format-version": "3.3.7",
  "start": "Start",
  "zoom": 1
}


:: Init [startup] {"position":"500,225","size":"100,100"}
(set: $handspace to 2)


:: Start {"position":"750,250","size":"100,100"}
Carrying: (print: 2-$handspace)

(if: $handspace > 0)[  (link:"Pick")[(set: $handspace to it -1)(goto: "Start")]  ]
(if: $handspace < 2)[  (link:"Drop")[(set: $handspace to it +1)(goto: "Start")]  ]

I’m new so I can’t really decipher this harlowe code, any chance you could put it in twine?

Hi, you can import the above code into Twine:

  1. Copy into a text file on notepad.
  2. Save as Inv.twee.
  3. Import from Twine library.

@Parils (and @n-n in regards to a “Link with Setter”)
A couple of points:

1: The triple back-quote ``` markers use by this forum’s Code Block markup need to be place at the start of an otherwise empty/blank line…
eg.
```
your code between the two lines that only contain the markers.
```

2: Many Harlowe macros (like (for:) and the (if:) family) need to be associated with a Hook.
eg. (if: $variable is "value")[content to process if the condition is true]

3: One of three “link” macros are generally used to create what’s knows as a “Link with Setter”, which you use depends on:

  • if a Passage Transition should also occur.
  • if the link can be selected multiple times without a Passage Transition occurring.

3a: The (link-reveal-goto:) macro is used if a Passage Transition is wanted.

(link-reveal-goto: "Pick", "Start")[(set: $handspace to it - 1)]

3b: The (link-repeat:) macro is used if multiple selections within the current Passage is wanted.

(link-repeat: "Add one to counter")[(set: $counter to it + 1)]

3c: The (link:) macro (aka (link-replace:)) is used in most other use cases.

(link: "Light the Lamp")[(set: $lampLit to true)]
2 Likes