Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[sugarcube 2] Any way to trigger additional code on transition?

So, I've got this situation where I'd like to do some checking of a textbox when I transition back, with a previous() link.

I know about setters, and I use a setter to change the string into a number (Number()), but I need to use comparison operators to do the next check. What I'm wanting to do is this:
<<if isNaN($number)>>
    <<set $number to $default>>

The tricky thing about this is that the passage in question is linked from a menu option, so I'd like to keep the previous() address intact.

So, from anywhere, they hit the "config" menu option and it takes them to a page they can set various things. When they've had enough, they hit "return". And it's on this transition that I'd like to do that check.

So, right now, I have:
[[return|previous()][$number to Number($number)]]

But I'd also like to do that other piece of code within the transition. Or, I could go to an intermediary passage to do it, but how to I then go back to the correct destination? That I don't know about.


  • edited November 2015
    I'd probably suggest using the <<click>> macro for what you've described. Additionally, you should also be checking for Infinity, rather than just NaN. For example:
    <<click [[Return|previous()]]>>
    	<<set $number to Number($number)>>
    	<<if isNaN($number) or not isFinite($number)>>
    		<<set $number to $default>>
  • Wow! That's pretty nice. I hadn't even thought of doing it that way. Thanks a lot.
Sign In or Register to comment.