Tabletop Playground

SimpleButtons for Tabletop Playground

Released (updated ago). Ranked 230 of 331 with 146 (0 today) downloads

Published by Salami_TTP (mod ID: 86564)

thumbnail.5.jpg

Simply Buttons! A simple script I made to compensate for the fact that there is no built-in way to easily create user-interactable buttons with little hassle. These could be fancier, especially if we could set models and such through scripting(could also doing it by cheekily swapping different objects I guess)

However, these are.. Simply Buttons.

Open the chat window to see output from buttons.

Click the green button enough times and it might do something cool!


The intended usage for this script is for you to have an object you want to turn into a button already made and ready, and then using makeButton or makeButtonByID to turn said object into a button. This will allow the button in question to have its own script and functionality.

Example Usage:

var buttons = require("simplybuttons")
// Require without adding script to your package folder (Still needs to be downloaded, just grabs the script from the downloaded modio folder)
// var buttons = require("../.modio/mods/86564/Scripts/simplybuttons.js")
// require script and directly use functions with makeButton/makeButtonByID
// const {makeButton, makeButtonByID} = require("simplybuttons")

// Make a button with only the uid; Equivalent to getting an object with world.getObjectById("UID_HERE") and passing it to makeButton
// Will print "button grabbed" when pressing the button, and "button released" when letting go. Second function is unneeded for a basic toggle button.
buttons.makeButtonByID("UID_HERE", function(gameObject, player) { console.log("button pressed") }, function() { console.log("button released") })

// Make a button with a reference to a GameObject. Will print "button grabbed" when pressing the button, and "button released" when letting go. Second function is unneeded for a basic toggle button.
buttons.makeButton(refObject, function(gameObject, player) { console.log("button pressed") }, function() { console.log("button released") })

Pastebin.com

The callbacks will allow you to run functionality when the button is pressed/released. The second callback is unneeded if you just want it to set a variable. You can also just take the simple functionality from lockEventGrab & lockEvenRelease to add to your own object and it'll work fine for preventing people from picking something up.

To see more examples of the script in action and how to use it, load the package game state "start" in the editor.


For developers:

If you wish to use this script in your own package, I recommend using the published node package rather than copying the file.

You can find binaries/installers for node here: Nodejs.org

This script's module name is @salami-ttp/simplybuttons

Once you have the binaries installed or already have them, go into your package's Scripts folder and open a command prompt/terminal window there.

You can install the package by typing npm install @salami-ttp/simplybuttons

You can then use the module in your package scripts like so: require("@salami-ttp/simplybuttons")

See global.js for example usage of the module.

Releases

FilenameSizeVersionAddedOptions
upload_86564_modfile.4.zip283.82kb1.2

upload_86564_modfile.3.zip293.54kb1.1.1

upload_86564_modfile.2.zip293.69kb1.1

upload_86564_modfile.1.zip292.67kb1.0.1

upload_86564_modfile.zip292.25kb1.0

Comments

Join the community or sign in with your gaming account to join the conversation:

Irene18
Irene18 @irene18

Thanks for this workaround till proper UI is delivered.
And thanks for the laughs induced by the button :D