Difference between revisions of "User:Tails"

From Multi Theft Auto: Wiki
Jump to: navigation, search
(Useful Functions created by Tails)
(Useful Functions created by Tails)
 
Line 1: Line 1:
==Useful Functions created by Tails==
 
<section name="check" class="both" show="false">
 
*[[check]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function checks if its arguments are of the right type and calls the error-function if one is not.</span>
 
<syntaxhighlight lang="lua">
 
function check(pattern, ...)
 
if type(pattern) ~= 'string' then check('s', pattern) end
 
local types = {s = "string", n = "number", b = "boolean", f = "function", t = "table", u = "userdata"}
 
for i=1, #pattern do
 
local c = pattern:sub(i,i)
 
local t = #arg > 0 and type(arg[i])
 
if not t then error('got pattern but missing args') end
 
if t ~= types[c] then error(("bad argument #%s to '%s' (%s expected, got %s)"):format(i, debug.getinfo(2, "n").name, types[c], tostring(t)), 3) end
 
end
 
end
 
</syntaxhighlight>
 
</section>
 
  
<section name="guiGridListGetColumnIDFromTitle" class="client" show="false">
 
*[[guiGridListGetColumnIDFromTitle]] <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;">» This function gets a gridlist's column ID from the column title.</span>
 
<syntaxhighlight lang="lua">
 
function guiGridListGetColumnIDFromTitle(gridlist, title)
 
for id=1, guiGridListGetColumnCount(gridlist) do
 
if guiGridListGetColumnTitle(gridlist, id) == title then
 
return id
 
end
 
end
 
return false
 
end
 
</syntaxhighlight>
 
</section>
 

Latest revision as of 17:16, 31 August 2018