User Tools

Site Tools


button

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
button [2020/11/30 22:46] justinbutton [2021/06/24 21:18] (current) justin
Line 6: Line 6:
 =====Element Properties===== =====Element Properties=====
 ^Icon^Property^Description^ ^Icon^Property^Description^
-|{{:wiki:tag_id.png?nolink|}}|Element ID|ID for the button. This ID must be unique amongst the other elements within the same [[widget]]. It is currently auto-generated but will be editable in a future update.+|{{:wiki:tag_id.png?nolink|}}|Element ID|ID for the button. This ID must be unique amongst other elements within the same [[widget]]. It is currently auto-generated but will be editable in a future update.|
 |{{:wiki:button.png?nolink|}}|Button Type|Determines whether the button will have standard behavior or if it will behave as a toggle button (i.e. the button toggles between an "on" and "off" state each time it's pressed).| |{{:wiki:button.png?nolink|}}|Button Type|Determines whether the button will have standard behavior or if it will behave as a toggle button (i.e. the button toggles between an "on" and "off" state each time it's pressed).|
 |{{:wiki:play.png?nolink|}}|Button Action|Determines what action will be taken when the button is pressed (only applicable to the "Standard" button type). The available options are to run a [[script]], close the parent [[widget]], craft a new [[item]] into a [[item_storage_slot|storage slot]] using any populated [[crafting_input_slot|input slots]], or craft a specific [[item]] using the player's [[inventory]].| |{{:wiki:play.png?nolink|}}|Button Action|Determines what action will be taken when the button is pressed (only applicable to the "Standard" button type). The available options are to run a [[script]], close the parent [[widget]], craft a new [[item]] into a [[item_storage_slot|storage slot]] using any populated [[crafting_input_slot|input slots]], or craft a specific [[item]] using the player's [[inventory]].|
-|{{:wiki:script.png?nolink|}}|Script|[[Script]] that will be triggered when the button is clicked. This option is only available when the button type is "Toggle" or the button type is "Standard" with an action of "Run Script"For toggle buttons, a local variable named **$pressed** will be available to your [[script]]. It will have a value of either true or false according to the new state of the button.|+|{{:wiki:script.png?nolink|}}|Script|[[Script]] that will be triggered when the button is clicked. This option is only available when the button type is "Toggle" or the button type is "Standard" with an action of "Run Script"In both cases, a local variable named **$widget** will be available to your [[script]] that references the [[widget]] in which the button is contained. The **self** keyword will reference the button element itself. For toggle buttons, a local variable named **$pressed** will also be available. It will have a value of either true or false according to the new state of the button (i.e. pressed or not pressed).|
 |{{:wiki:item.png?nolink|}}|Item|[[Item]] that the game will attempt to craft using the player's [[inventory]] when the button is clicked. This option is only available when the button type is "Standard" with an action of "Craft Item by ID".| |{{:wiki:item.png?nolink|}}|Item|[[Item]] that the game will attempt to craft using the player's [[inventory]] when the button is clicked. This option is only available when the button type is "Standard" with an action of "Craft Item by ID".|
 |{{:wiki:image.png?nolink|}}|Image|[[Image]] that will be displayed on the button. If an [[image]] is specified, it will appear to the left of the button's text.| |{{:wiki:image.png?nolink|}}|Image|[[Image]] that will be displayed on the button. If an [[image]] is specified, it will appear to the left of the button's text.|
Line 18: Line 18:
  
 =====Scripting===== =====Scripting=====
-You can access and change certain properties of a button from within a [[script]] by simply referencing the parent [[widget]] by ID followed by a reference to the button element by ID.+You can access and change certain properties of a button from within a [[script]] by simply referencing the parent [[widget]] and the button element by their unique IDs. See below for examples of changing the text, [[image]], and [[script]] of a button. In these cases, the [[widget]] has an ID of "test" and the button has an ID of "0001".
  
-Changing a button's text:+**Changing a button's text:**
 <code bauxite> <code bauxite>
-widget["test"].element["0001"].text = "New Text"+widget["test"].element["0001"].text = "New Text";
 </code> </code>
  
-Changing a button's image:+**Changing a button's image:**
 <code bauxite> <code bauxite>
-widget["test"].element["0001"].image = "new_image.png"+widget["test"].element["0001"].image = "new_image.png";
 </code> </code>
  
-Changing a button's script:+**Changing a button's script:**
 <code bauxite> <code bauxite>
-widget["test"].element["0001"].script = "new_script_name"+widget["test"].element["0001"].script = "new_script_name";
 </code> </code>
  
 ~~NOTOC~~ ~~NOTOC~~
button.1606805212.txt.gz · Last modified: 2020/11/30 22:46 by justin