monumento Posted April 8, 2014 Share Posted April 8, 2014 (edited) 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 April 8, 2014 by Guest Link to comment
Castillo Posted April 8, 2014 Share Posted April 8, 2014 Simply execute "showMissionWindow" and pass two arguments: showMissionWindow ( "Argument 1", "Argument 2" ) Link to comment
monumento Posted April 8, 2014 Author Share Posted April 8, 2014 (edited) 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 ? Edited April 8, 2014 by Guest Link to comment
Castillo Posted April 8, 2014 Share Posted April 8, 2014 I really don't get what you are saying. About the Lua tags, use code=lua instead of code=text. Link to comment
monumento Posted April 8, 2014 Author Share Posted April 8, 2014 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
Castillo Posted April 8, 2014 Share Posted April 8, 2014 No, you can't pass arguments with event handlers, but you can store the data somewhere, like in a variable. Link to comment
monumento Posted April 8, 2014 Author Share Posted April 8, 2014 Can you explain me how can i do it? Thanks! Link to comment
Moderators IIYAMA Posted April 11, 2014 Moderators Share Posted April 11, 2014 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
monumento Posted April 11, 2014 Author Share Posted April 11, 2014 Thanks! I owe you a beer. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now