Widget works partially

Hi,
I have a widget that is triggered by a link with no passage included. It runs in the StoryCaption passage. _passage is set to passage().

<<link [[Level|_passage]]>><<level>><</link>>

The $gc.hookLevel conditional statement fires and the variable is updated but the $player.level is not. The widget is basically a toggle, if that helps.
I have tried every which way to Sunday to make this work. I don’t understand why the $gc.hookLevel variable is updated but not the $player.level. $gc.ride is true, FYI.
I have already tried to set the $player.level to “catwalk” or “floor” as appropriate. Still won’t budge. :frowning:

:: level [widget]
<<nobr>>
<<widget "level">>
<<if $gc.state is "on">>
<<if $gc.hookLevel eq "floor">><<set $gc.hookLevel to "catwalk">><<else>><<set $gc.hookLevel to "floor">><</if>>
<<if $gc.ride is true>><<set $player.level to $gc.hookLevel>><</if>>
<</if>>
<</widget>>
<</nobr>>

Any help is appreciated!
Deborah

1 Like

My best guess is that there’s something about $gc.ride that is causing that conditional to always evaluate to false. It could be something as simple as typing <<set $gc.ride = "true">> instead of <<set $gc.ride = true>> since those two are different data types, and if you’re using the is command it’ll be checking for strict equality. If you use eq or == then it’ll just check for equivalence instead and it’ll attempt to ignore types. (The Sugarcube documentation on conditional operators generally doesn’t recommend using eq but sometimes you gotta).

I have also occasionally had issues with data typing using objects where things I put in one all become strings whether I like it or not, so that could be the source of the issue as well.

I am very tired right now so I hope I am getting this right! Either way, I’d recommend either changing the statement’s operator from is to eq and see if anything changes, or you can use the Javascript operator typeof on $gc.ride. Fingers crossed this fixes your problem since I have no idea what else may be causing it, but at the very least eliminating this as a possibility will be useful.

1 Like

notes:

  1. if you assign the special nobr Passage Tag to the Passage containing your widget definitions then you don’t need to wrap those definitions in a <<nobr>> macro call.
  2. As the Twine 2.x application can’t correctly show a Connection arrow for your Level link, you might as well use the variant of the <<link>> macro that you pass the Link Label & Target Passage as String arguments.
  3. You shouldn’t use is true or is false when checking the current value of a Boolean variable or property, as that adds an additional step to the comparison.
  4. I also tested exact copies of your code examples, and they produced the same outcomes as my variant of them.

I created the following basic SugarCube based project…
(example is using Twee Notation)

:: StoryInit
<<set $gc to {
	state: "on",
	hookLevel: "floor",
	ride: true
}>>
<<set $player to {level: "floor"}>>

:: StoryWidgets [widget nobr]
<<widget "level">>
	<<if $gc.state is "on">>
		<<if $gc.hookLevel is "floor">>
			<<set $gc.hookLevel to "catwalk">>
		<<else>>
			<<set $gc.hookLevel to "floor">>
		<</if>>
		<<if $gc.ride>>
			<<set $player.level to $gc.hookLevel>>
		<</if>>
	<</if>>
<</widget>>

:: StoryCaption
<<link "Level" _passage>><<level>><</link>>

:: Start
Welcome to the test
<<set _passage to passage()>>

…and then Played the project and selected the Level link

When I used the Console of my Web-developer Developer Tools and the undocumented SugarCube debug interface to check what the new values of both the $gc and $player variables were, I saw they had changed to…

$gc => {state: 'on', hookLevel: 'catwalk', ride: true}
$player => {level: 'catwalk'}

…so the widget seems to be working correctly.

How exactly did you test to see if the widget was working?

Thank you for the notes, they are very helpful.

I’m using the Debug Bar and I’m still seeing the same results.
I do have Firefox Developer as well.

UPDATE: The variable is updating as expected. I printed the output in the body of the passage to see the result instead of just using the Debug Bar. Not sure why it isn’t updating there.

Thanks for your help.

Deborah

Prior to v2.37.x the debug bar only updated its variable watches on passage transition.

With v2.37.0, and later versions, the debug bar updates its variable watches routinely—roughly every 200 milliseconds.

1 Like