Results 1 to 3 of 3

Thread: Want to use self.setVariable and get button click parameters too

  1. #1

    Question Want to use self.setVariable and get button click parameters too

    In the process of making a character sheet, I've been told that my up-and-down two button system (3 for the display) would be much better received as a single one that you left click to increment and right click to decrement. To fit the many buttons in the script, they're made from a function and their click_function is a string amplified with setVariable at the time of ordering. This is because you can't pass parameters through the click_function string without doing that first. However, now I can't receive the parameters that usually result from clicking a button, which I need to do in order to get the third option which determines if the button was left or right clicked.

    Sorry if I drown out your scrollbar with this, but I'll post some longform examples of what I'm on about.

    Code:
    function placeabutton(id, xpo, zpo)
        catalog[id] = {}
        catalog[id].value = '5'
    
        catalog[id].index = markindex
        markindex = markindex + 1
        catalog[id].click_function = tostring(id) .. 'duplectact'
        catalog[id].function_owner = self
        catalog[id].label = tostring(catalog[id].value)
        catalog[id].position = {xpo,0.25,zpo}
        catalog[id].width = 200
        catalog[id].height = 200
        catalog[id].color = {0,0,0,0}
        catalog[id].font_size = 200
        catalog[id].font_color = {1,1,1,95}
        self.setVar(tostring(id) .. 'duplectact', function () duplex(id) end)
    end
    
    function duplex(_obj, _col, _altclick, id)
        val = catalog[id].value
        mod = _altclick and -1 or 1
        new_value = val + mod
        if val ~= new_value then
            val = new_value
            updateVal(id, new_value)
        end
    end
    
    function updateVal(id, mth)
        catalog[id].value = mth
        catalog[id].label = catalog[id].value
        self.editButton(catalog[id])
    end
    You can see the problem lies in having to pre-define the parameters before clicking, and then the parameters I also need are generated at the time of clicking.

    You can also probably see that I hawked most of this code from the only sample of this system I was able to find in the 'Better notecards and counters' by Idan

    So what I need is genuine magic. A magic variable to let the system know it needs to fill in 3 params on its own, and then let me define the fourth one with whatever I want.

    I've tried
    Code:
    self.setVar(tostring(id) .. 'duplectact', function () duplex(nil,nil,nil,id) end)
    hoping it would fill the nil
    I've tried
    Code:
    self.setVar(tostring(id) .. 'duplectact', function () duplex( , , ,id) end)
    and got an error, since you can't just have spaces
    I've tried
    Code:
    self.setVar(tostring(id) .. 'duplectact', function () duplex(id) end)
    like in the example code above but still the rest return nils, and the first param _obj takes the form of id, which is to be expected

    For a little more info, I can make the button go up by clicking left or right. It doesn't seem to be able to go down as a result of my param juggling.

    So I'm pretty sure I ran into one of very few limitations of TTSLua and I'll either have to define each button's click_function separately and not use self.setVariable, or define each button's click_function separately and not use self.setVariable. I'm not too worried about this right now because I can work on other angles of this project until I either get Holy Deliverance from someone reading or Ęternal Damnation to the noodly workaround.
    Last edited by popcorn7915; 01-11-2019 at 03:18 PM. Reason: SOLVED

  2. #2
    Code:
    self.setVar(name, function(obj, col, alt) duplex(obj, col, alt, id) end)
    -- or, actual pure Lua syntax
    _G[name] = function(obj, col, alt) duplex(obj, col, alt, id) end
    You need to add those args to the function so theyre passed and not discarded

  3. #3
    That did it! Thanks, champion!
    Always seems like when I need something it's just the tiniest piece of info out of reach that I haven't yet figured out the intricacies of

    This is gonna save me oodles of load time

Similar Threads

  1. Can't Click Object Button
    By essbess in forum Scripting
    Replies: 14
    Last Post: 09-10-2017, 08:33 PM
  2. Make button click functions return button parameters and/or index
    By MrStump in forum Scripting Suggestions
    Replies: 0
    Last Post: 05-16-2017, 10:10 PM
  3. [ADDED] Add scale to button parameters
    By MrStump in forum Scripting Suggestions
    Replies: 4
    Last Post: 03-26-2017, 04:07 AM
  4. Passing parameters to button's click_function
    By Didero in forum Scripting Suggestions
    Replies: 2
    Last Post: 03-24-2017, 10:09 AM
  5. Add parameters.parameters to button parameters.
    By MrStump in forum Suggestions
    Replies: 0
    Last Post: 07-03-2016, 11:23 AM

Tags for this Thread

Posting Permissions

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