1.6 KiB
IMappetUIContext.sendToPlayer
Parça 3/3 · önceki
Returns a UI component by given ID or null. You can use this in the handler script of the UI to change certain properties.
function main(c) { var ui = mappet.createUI(c, "handler").background(); var button = ui.button("Push me").id("button");
// Place a button in the middle of the screen button.rxy(0.5, 0.5).wh(80, 20).anchor(0.5); c.getSubject().openUI(ui); }
function handler(c) { var uiContext = c.getSubject().getUIContext();
if (uiContext.getLast() === "button") {
uiContext.get("button").label("Push me harder!"); } }
sendToPlayer
void sendToPlayer()
Sends UI changes to the player.
If you edited the UI context's component data using get(String) outside of the UI handler script (UI context, after executing the handler script, sends the changed data afterwards automatically), you need to manually send the data to the player using this function.
// ui.js function main(c) { var ui = mappet.createUI().background(); var button = ui.button("Push me").id("button");
// Place a button in the middle of the screen button.rxy(0.5, 0.5).wh(80, 20).anchor(0.5); c.getSubject().openUI(ui); }
// other.js function main(c) { var uiContext = c.getSubject().getUIContext();
// Assuming that UI context is still present (i.e. the UI is still open) if (uiContext) { uiContext.get("button").label("Too late!"); uiContext.sendToPlayer(); } }