Howdy, Stranger!

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

Add clickhandler doesn't seem to be working.

I've been using the add clickhandler function to make my own save, restart, and options buttons. With the new update to Sugarcube, the clickhandler functions don't seem to work anymore. It gives an error message saying that there was a Type error, undefined is not a function. It worked perfectly before, so I'm guessing that now there's a new way to write this, but I don't know what it is.

The old code I was using is
$("body").append("<button id='save-sub'>Save/Load</button>");
UISystem.addClickHandler("#save-sub", null, function () { UISystem.buildSaves(); });

$("body").append("<button id='restart-sub'>Restart</button>");
UISystem.addClickHandler("#restart-sub", null, function () { UISystem.buildRestart(); });

$("body").append("<button id='sound-sub'>Sound</button>");
UISystem.addClickHandler("#sound-sub", null, function () { UISystem.buildOptions(); });

Comments

  • Yeah, the non-public API changed.  The UISystem.build() static methods had their names altered.  The new names follow the form UISystem.buildDialog() (e.g. UISystem.buildDialogSaves()).

    Beyond that, I'm not sure if your above example is your exact code or not, however, you don't need (or really want) three jQuery calls to do (essentially) one thing.  You might be better served by something like this:

    // I left a space between the <button> elements for show, if that causes an issue with your styling, just remove them
    $("body").append('<button id="save-sub">Save/Load</button> <button id="restart-sub">Restart</button> <button id="sound-sub">Sound</button>');
    UISystem.addClickHandler("#save-sub", null, function () { UISystem.buildDialogSaves(); });
    UISystem.addClickHandler("#restart-sub", null, function () { UISystem.buildDialogRestart(); });
    UISystem.addClickHandler("#sound-sub", null, function () { UISystem.buildDialogOptions(); });
  • Yeah, that's a lot quicker to write. Thank you for the help!
Sign In or Register to comment.