Hello all.
I'm creating a function that the parameters are functions (or maybe it called callback? idk)
What i'm going to do is creating a function that creates buttons and do some dxdraw, but with a handler, and exports the function so i can reuse it whenever i need it.
The problem is the function is returning nil.
I've read in another forums, it said " Lua functions are just values, and you can asssign them using their name without paren" Link
But it doesnt work.
Here the codes (I simplify it)
local messages = {}
function drawConfirmationButton( )
for k,message in ipairs( messages ) do
if ( message[2] ) and ( message[3] ) then
destroyElement( message[2] )
destroyElement( message[3] )
end
message[2] = guiCreateButton(--[[blabla]])
message[3] = guiCreateButton(--[[blabla]])
addEventHandler( "onClientGUIClick", message[2], message[4] )
addEventHandler( "onClientGUIClick", message[3], message[5] )
end
end
function createConfirmations( m, onAccept, onReject )
-- i've been log the onAccept and onReject and it return nil
table.insert( messages, { m, acceptButton, rejectButton, onAccept, onReject } )
addEventHandler( "onClientRender", root, drawConfirmation )
drawConfirmationButton()
end
Use it in another file.
exports.common:createConfirmations( "Accept the request?", function() --[[code here]] end, function() --[[code here]] end )
Maybe some of you can help me or maybe another methods.
Thanks for your attentions, sorry for my bad English