description
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") })
https://pastebin.com/raw/7cpqSBQU
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: https://nodejs.org/en/
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.
Credits
-
27 Jul 19:48Version 1.2
Removed workaround for weird garbage collection issue, fixed/improved docs, published as node package @salami-ttp/simplybuttons
0 Comments for SimpleButtons