Jump to content

Function not return value


drk

Recommended Posts

I created a function to generate a code, then return the result but it don't return nothing, I get "..code.." instead of result. And now I get error on account argument ( a userdata value )

code:

function generateCode() 
    local number1 = math.random(20,40) 
    local number2 = math.random(100,900) 
    local number3 = math.random(100,900) 
    local result = number1.."."..number2.."."..number3 
    return result 
end 
  
addEventHandler('onPlayerLogin',root, 
    function(_,account) 
        local select = executeSQLQuery("SELECT * FROM Phone WHERE player='"..account.."'") 
        if not select or #select == 0 then 
            local code = generateCode() 
            executeSQLQuery("INSERT INTO Phone VALUES ( '"..account.."','"..code.."' )") 
            local select2 = executeSQLQuery("SELECT number FROM Phone WHERE player='"..account.."'") 
            outputChatBox('#ABCDEF* #ffffffYour phone number is: '..select2[1]['number'],source,255,255,255,true) 
        else 
            local select3 = executeSQLQuery("SELECT number FROM Phone WHERE player='"..account.."'") 
            outputChatBox('#ABCDEF* #ffffffYour phone number is: '..select3[1]['number'],source,255,255,255,true) 
        end 
    end 
) 
  

Link to comment
function generateCode() 
    local number1 = math.random(20, 40) 
    local number2 = math.random(100, 900) 
    local number3 = math.random(100, 900) 
    local result = number1.."."..number2.."."..number3 
    return result 
end 
  
addEventHandler('onPlayerLogin',root, 
    function(_,account) 
        local select = executeSQLQuery("SELECT * FROM Phone WHERE player='".. getAccountName(account) .."'") -- Account returns an account userdata, not an account name. 
        if not select or #select == 0 then 
            local code = generateCode() 
            executeSQLQuery("INSERT INTO Phone VALUES ( '".. getAccountName(account) .."','".. code .."' )") 
            local select2 = executeSQLQuery("SELECT number FROM Phone WHERE player='".. getAccountName(account) .."'") 
            outputChatBox('#ABCDEF* #ffffffYour phone number is: '..select2[1]['number'],source,255,255,255,true) 
        else 
            local select3 = executeSQLQuery("SELECT number FROM Phone WHERE player='".. getAccountName(account) .."'") 
            outputChatBox('#ABCDEF* #ffffffYour phone number is: '..select3[1]['number'],source,255,255,255,true) 
        end 
    end 
) 

Link to comment
And now I get error on account argument ( a userdata value )

Yeah, because in event onPlayerLogin 2 argument is account ( element ) ( userdata ).

So you need get name account from account ( element ) ( userdata ).

  
addEventHandler( 'onPlayerLogin',root, 
    function( _,account ) -- account variable is ( element ) ( userdata ). 
        outputChatBox( 'Account Name is '..getAccountName( account ) ) -- getAccountName function return string with account name. 
    end 
)  
  

Example

Link to comment
And now I get error on account argument ( a userdata value )

Yeah, because in event onPlayerLogin 2 argument is account ( element ) ( userdata ).

So you need get name account from account ( element ) ( userdata ).

  
addEventHandler( 'onPlayerLogin',root, 
    function( _,account ) -- account variable is ( element ) ( userdata ). 
        outputChatBox( 'Account Name is '..getAccountName( account ) ) -- getAccountName function return string with account name. 
    end 
)  
  

Example

No need to explain but thanks too :D

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...