Jump to content

Origin of a function call


Recommended Posts

Hey Guys,

I want get the origin of a function call to output it in a debugscript!

Im using this little function:

  
function MySQL_Save ( strings ) 
    return mysql_escape_string ( Datenbank, strings ) 
end 
  

But if i call this function by a wrong parameter i get the error every time in this line: "return mysql_escape_string ( Datenbank, strings )" and i dont know where the origin of the error is...

Link to comment

This should be in the scripting forum.

Anyway, you can add a check and then use your own error output in debug. Example:

      
function MySQL_Save ( strings ) 
    if not strings then 
        outputDebugString("MySQL_Save: no argument", 3) 
        return false 
    elseif type(strings) ~= 'string' then 
        outputDebugString("MySQL_Save: arg #1 not a string", 3) 
        return false 
    elseif #strings < 1 then 
        outputDebugString("MySQL_Save: invalid string", 3) 
        return false 
    end 
    return mysql_escape_string ( Datenbank, strings ) 
end 

You can find an advanced function for argument checking here: https://wiki.multitheftauto.com/wiki/Check

Link to comment
This should be in the scripting forum.

Anyway, you can add a check and then use your own error output in debug. Example:

      
function MySQL_Save ( strings ) 
    if not strings then 
        outputDebugString("MySQL_Save: no argument", 3) 
        return false 
    elseif type(strings) ~= 'string' then 
        outputDebugString("MySQL_Save: arg #1 not a string", 3) 
        return false 
    elseif #strings < 1 then 
        outputDebugString("MySQL_Save: invalid string", 3) 
        return false 
    end 
    return mysql_escape_string ( Datenbank, strings ) 
end 

You can find an advanced function for argument checking here: https://wiki.multitheftauto.com/wiki/Check

Yeah i know these functions...

But here you have an example:

  
function test() 
     thefunction("huhu") -- here i want a error 
end 
addCommandHandler("test",test) 
  
function thefunction(int) 
     if(type(int) == "string") then 
             outputDebugString("Don't use Strings!", 3)   -- I get the Error in this line, but i want it in this line : "thefunction("huhu")" . I dont know here where the function was called... 
     end 
end 
  

Link to comment
  • Recently Browsing   0 members

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