I'm using twine 2 - online/browser based
Sugarcube 1
So I'll set
$self_worth
at the start of my story. I display that and other variables' values in the sidebar with StoryMenu
Later on in the story I'll use a setter link to change that variable.
like so..
* goes very well, [[and she confronts Dean|break up or not][$self_worth -= 5]]
in the next passage, the $self_worth value no longer displays in the sidebar.
When I try to manipulate the $self_worth variable to see whats going on...
<<set self_worth -= 5>>
I get this error:
Error: <<set>>: bad evaluation: self_worth is not defined.
Why is the setter link unsetting my variable, what am I doing wrong?
Comments
Instead of: You should have done:
You should likely ensure that you aren't doing that elsewhere.
It's the <<set>> macro you gaffed on (as shown below). Whether just here or also in your code, I couldn't say. Though, going by the error message, I'd say in your code as well (error: "bad evaluation: self_worth is not defined"; note the missing sigil).
That was just a test though. So my error message is gone, but if I try to print that variable nothing prints to the screen, which leads me to believe I'm unsetting it somehow.
<<set
$agency = 40,
$self_worth = 50,
$selflessness = 30,
$janelle_rapport = 50
>>
Let's say at this point in the story the self worth stat is at 55, if I use the above code the stat remains at 55, if I use the setter code, it isn't even set to 0, nothing prints at all =/
Use Twine 2's Import From File option to add the example to your Storyies list.
I'm going to try using the above archive file though. I think I might post my own archive file later.
So in an earlier passage I have this code.
If this code is not present the setter link won't unset the self worth variable.
I think I'm just going to avoid doing the above (this isn't a good means of doing what I want to do) from now on, so we could close the issue, but if anyone knows why the above code is problematic please let me know.
For example, instead of this: You should be doing the following:
As a general rule: Never quote variables passed as arguments to a macro unless the macro's documentation specifically tells you to, and only the specific variables you are told to. Specifically, the only macros which require this are the various input macros (e.g. <<checkbox>>, <<radiobutton>>, <<textbox>>, etc), and then you only quote the receiver variable.
The reason the value of $self_worth was disappearing from the UI bar is that by the time your setter link is clicked the $self_worth variable was set to a string (one of: "$sw_change_1", "$sw_change_2", "$sw_change_3"). So, the expression ($self_worth -= 5) was actually try to do something like, $self_worth = "$sw_change_1" - 5, which is nonsensical and yields NaN (Not a Number). NaN, along with a few other special values, doesn't have a printed form (i.e. nothing will print).
@cocoaflannel:
Assuming you have previously assigned a numeric value to the $self_worth before hand because an undefined variable does not equal zero, then your example works.
note: You don't need to wrap the $sw_change_1, $sw_change_2, $sw_change_3 variables in quotes when you pass their value to the <<radiobutton>> macro, this only needs to be done to the first parameter.