0 votes
by (590 points)
edited by
Hello, I read that temporary variables only exist within the same passage, hook, or lambda, but when i try using them in this way it seems they stop existing much sooner than this. nothing works with them, i set temporary variables and then try calling upn them later in the passage and they are already dead.

do i just need to turn the entire passage into a hook to force the temporary variables to hang around longer? i need them to hang around for the passage

also it seems variables cannot be solely named using numerics, like _1 $3 _0 $10. i guess this is because if you ever wanted to print "$34" (34 dollars) it would conflict with the variabled named 34. anyway that is beside the point, but i never saw anything about that in the manual.

help is appreciated, thanks

1 Answer

0 votes
by (159k points)

variables cannot be solely named using numerics

Unfortunately the Harlowe variable related documentation is missing some information about naming conventions, and it seems it assume that you have read the older Twine 1 documentation related to this subject. I strongly suggest you create a new issue on the Harlowe project's repository so that the developer can know about this omission and can rectify it.

i try using them in this way it seems they stop existing much sooner than this

You didn't supply an example of a case (or cases) where you found that a temporary variable was no longer available, which means that anyone answering your question needs to guess (via trial and error) what you were doing to achieve that outcome.

The following very simple example shows that a temporary variable can be set and then referenced later in the same passage.

(set: _var to "a value")

"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

test 1: var: _var
test 2: (if: _var is "a value")[the var equals a value]

edit:

Variables can have different scopes (global, local, etc..) depending on their type (story or temporary) and where/how they are initialised (within a passage, a (for:) macro, a lambda, etc...)

by (590 points)
yikes you're right, they work for me now. i was using numeric names and this probably caused the problem. i made the mention in the post just because i found it strange, but that was actually my primary problem. but i never simply changed to alphanumeric names to test it, i changed them to permanent variabled with alphanumeric names in a single step and assumed the change to permanent variables was the fix. thanks! i'll do as you say about submitting the issue as well
...