Results 1 to 2 of 2

Thread: How do i get a reference from the button i pressed?

  1. #1

    How do i get a reference from the button i pressed?

    Hello everyone,

    Say i have an object with LOTS of .createbutton() on it.

    Do i have to make a single function for each button even though their resolution is similar? Couldn't we get a "function_parameters" on it to pass info so the function would know what to do?

    Yeah i know the click_function automatically runs the function with "Object" and "Player Who Clicked" as both parameters, but the object one only returns userdata from the actual object i have the button on, not the button itself, this doesn't seem to help my case.

    If anyone have managed to workaround this, please share with me your secrets of trade.UC browser SHAREit Appvn


    Thank you!
    Last edited by david77; 05-12-2019 at 02:43 PM.

  2. #2
    As far as I know the .createbutton() does not support. However, if you use the UI API (i.e. the xml UI tab) to create your buttons then you can do this.

    When you call a function from the UI, the third parameter is the id of the UI element. You can then use UI.getAttribute(id,"attribName") to read any attribute of the UI element (i.e. button) that was triggered. By setting a unique property for each of the buttons, a single common callback function can handle all of the button presses. I do this for my die rolling macros.

    Consider the following UI elements:

    Code:
    <Button class="Die" onClick="RollDie" sides="4" text="D4" />
    <Button class="Die" onClick="RollDie" sides="6" text="D6" />
    <Button class="Die" onClick="RollDie" sides="8" text="D8" />
    <Button class="Die" onClick="RollDie" sides="10" text="D10" />
    <Button class="Die" onClick="RollDie" sides="12" text="D12" />
    <Button class="Die" onClick="RollDie" sides="20" text="D20" />
    All of the above buttons use the same function (RollDie) but by providing either the sides property or the text property, the RollDie function can do either UI.getAttribute(id,"sides") or UI.getAttributes(id,"text") to distinguish between which button was clicked.

Similar Threads

  1. Replies: 6
    Last Post: 11-11-2017, 08:40 AM
  2. SteamOS version (Linux) doesn't zoom when 'M' is pressed
    By jlineberry in forum Technical Support
    Replies: 0
    Last Post: 05-11-2017, 10:21 PM
  3. Show List of All Stacked Counters When Alt is Pressed
    By CounterFactorian in forum Suggestions
    Replies: 0
    Last Post: 09-29-2016, 06:23 PM
  4. Way to get button pressed?
    By allencoded in forum Scripting
    Replies: 10
    Last Post: 06-05-2016, 07:19 AM
  5. Replies: 1
    Last Post: 08-17-2015, 05:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •