Howdy, Stranger!

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

SugarCube 2: combining click and back macros?

edited July 2016 in Help! with 2.0
I am using the <<click>> macro to fire a sound effect when the player clicks on a button, but I'm having difficulty getting this to work with the button I've set up to undo choices. It works fine progressing forward:
<<click "Continue" "Start3">><<playsound $buttonGo>><</click>>

But it breaks when I try to undo:
<<click "⇦ Undo" "back">><<playsound $buttonBack>><</click>>

It either looks for a passage titled back when I use quotes, or throws up an error if I don't. I've looked at the other macros available and can't seem to figure out the best way to incorporate this.

Any ideas?

Comments

  • Undo is a separate macro. Therefore, you should put it inside the click, not in the click macro.

    Eg

    <<click "Go Back">><<playsound>><<undo>><</click>>
  • edited July 2016
    I get this when I do what you suggest:
    Apologies! An error has occurred. You may be able to continue, but some parts may not work properly.
    
    Error: macro <<undo>> does not exist.
    
    Stack Trace:
    Error: macro <<undo>> does not exist
        at Function._createClass.value (<anonymous>:39:15739)
        at HTMLAnchorElement.<anonymous> (<anonymous>:40:10822)
        at HTMLAnchorElement.<anonymous> (<anonymous>:38:13828)
        at HTMLAnchorElement.n.event.dispatch (<anonymous>:24:7516)
        at HTMLAnchorElement.r.handle (<anonymous>:24:5597)
    

    I replaced undo with the back macro, which doesn't return an error but also doesn't do anything either unfortunately. The button/link is there, but it's non-functional.
  • The back macro as it is written seems to be a click macro in itself. Therefore, you won't be able to include it in a click macro. You might be able to write your own macro using the API, but TheMadExile will know more about what's possible.
  • Yeah I'd worked out that much sadly, I was trying to see if there was a way to merge the two together.
  • A quick look at the Engine API documentation lists a Engine.backward() function.

    So something like the following:
    <<click "Go Back">><<playsound>><<run Engine.backward()>><</click>>
    
  • Oh excellent, that seemed to do the trick! Are there any issues using that macro vs something else?

    Also does this correctly "undo" and go back a passage (IE, wiping it from history) or does it just press forward to the previous passage? I couldn't quite determine it from that documentation explanation.
  • edited July 2016
    It directly states that it undoes, not adds anything to history.

    "Rewinds the full history by one moment (i.e. undoes the moment)"
Sign In or Register to comment.