WoW:USERAPI GetReturnValues: Difference between revisions

m
Move page script moved page USERAPI GetReturnValues to WoW:USERAPI GetReturnValues without leaving a redirect
No edit summary
m (Move page script moved page USERAPI GetReturnValues to WoW:USERAPI GetReturnValues without leaving a redirect)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{userfunc}} <!-- Leave this line in! -->
{{userfunc}} <!-- Leave this line in! -->
<center>'''{{PAGENAME}}''' ''- by [[User:Egingell|Egingell]] -''</center>


Returns a list of values in whatever order you specify in ''order'' and only those you specify in ''order''. Mostly useful for functions that return multiple values.
Returns a list of values in whatever order you specify in ''order'' and only those you specify in ''order''. Mostly useful for functions that return multiple values.
Line 43: Line 41:
<!-- Paste your function(s) here. Make sure to prefix each line with at least one space. You may want to replace some troublesome characters with HTML entities when necessary, e.g. "<" becomes &lt;, etc.. -->
<!-- Paste your function(s) here. Make sure to prefix each line with at least one space. You may want to replace some troublesome characters with HTML entities when necessary, e.g. "<" becomes &lt;, etc.. -->


local output = {}
  function {{PAGENAME}}(order, ...)
  function {{PAGENAME}}(order, ...)
     local input = {...}
     output = wipe(output)
    local output = {}
     order = tostring(order)
    order = tostring(order);
    for i=1, strlen(order) do
        local key = tonumber(strsub(order, i, i));
        if input[key] ~= nil then
            table.insert(output, input[key]);
        end
    end
    return unpack(output);
end
Variant
local {{PAGENAME}}_In;
local {{PAGENAME}}_Out;
function {{PAGENAME}}(order, ...)
    {{PAGENAME}}_In = {...}
    {{PAGENAME}}_Out = {}
     order = tostring(order);
     for i=1, strlen(order) do
     for i=1, strlen(order) do
         local key = tonumber(strsub(order, i, i));
         local value = select(tonumber(strsub(order, i, i)), ...)
         if {{PAGENAME}}_In[key] ~= nil then
         if value ~= nil then
             table.insert({{PAGENAME}}_Out, {{PAGENAME}}_In[key]);
             table.insert(output, value)
         end
         end
     end
     end
     return unpack({{PAGENAME}}_Out);
     return unpack(output)
  end
  end


__NOTOC__
__NOTOC__
[[Category:User Defined Functions]]
[[Category:User defined functions]]
Anonymous user