Jump to content

Passing variables to button.


monumento

Recommended Posts

How can i pass some variables to button? Look.

gui["przyjmijMisje"] = guiCreateButton(10, 205, 111, 23, "Take mission", false, gui["glowne"]) 
    addEventHandler( "onClientGUIClick", gui["przyjmijMisje"], supkaFunkcja) 

It's ok. But in opening mission window i have some arguments (for example. value1)

function showMissionWindow(who, value1) 
-- other code 
gui["przyjmijMisje"] = guiCreateButton(10, 205, 111, 23, "Take mission", false, gui["glowne"]) 
addEventHandler( "onClientGUIClick", gui["przyjmijMisje"], supkaFunkcja) 
-- othercode 
end 

And the button function

function supkaFunkcja(button, state, absoluteX, absoluteY, pickupx) 
    if (button ~= "left") or (state ~= "up") then 
        return 
    end 
end 

Can i smuggle those arguments to the button function? Thanks for helping me, guys. I cant work it out

Edited by Guest
Link to comment

Yep. I know how to execute it. But i have the button:

gui["przyjmijMisje"] = guiCreateButton(10, 205, 111, 23, "Take mission", false, gui["glowne"]) 

(sorry, the .lua bbcode isnt working for me)

And

addEventHandler( "onClientGUIClick", gui["przyjmijMisje"], supkaFunkcja)

Now i want those arguments in the supkaFunkcja. How can i put them in the

function supkaFunkcja(button, state, absoluteX, absoluteY) 
if (button ~= "left") or (state ~= "up") then 
return 
end 
end 

? :x

Edited by Guest
Link to comment

Okay. So maybe i'll try to explain this by that:

  
function showMissionWindow(who, value1, value2) 
--window showing and other shit here 
gui["przyjmijMisje"] = guiCreateButton(10, 205, 111, 23, "Take mission", false, gui["glowne"]) 
addEventHandler( "onClientGUIClick", gui["przyjmijMisje"], supkaFunkcja) 
end 
  
function supkaFunkcja(button, state, absoluteX, absoluteY) 
        outputChatBox(tostring(value1)) -- showing value1 var from showMissionWindow 
end 
  

It is possible to do something like that? :)

Link to comment
  • Moderators
Bumping thread.

A table.

  
local buttonDataTable = {} 
  
function showMissionWindow(who, value1, value2) 
    --window showing and other :~ here 
    gui["przyjmijMisje"] = guiCreateButton(10, 205, 111, 23, "Take mission", false, gui["glowne"]) 
    addEventHandler( "onClientGUIClick", gui["przyjmijMisje"], supkaFunkcja) 
     
    buttonDataTable[ gui["przyjmijMisje"] ]= {value1, value2} -- store 
end 
  
function supkaFunkcja(button, state, absoluteX, absoluteY) 
    local buttonData = buttonDataTable[source] -- request 
    if buttonData then -- check 
        outputChatBox(tostring(buttonData[1]) .. " " .. tostring(buttonData[2])) -- showing value1 and value2 var from showMissionWindow 
    end 
end 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...