Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to make a function or ModuleScript return multiple values? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

Let's pretend I have a ModuleScript MultiReturnModule.

It has two things that it wants to send to other scripts: the value PartCount

PartCount = 0
for i,v in pairs(Workspace:GetDescendants())  do -- doot
    if part:IsA("BasePart") then -- if izza part
        PartCount = PartCount + 1 -- 1UP
    end
end

and the boolean

true

Is it possible that it could return both of these values having to group them together and probably putting true into a variable? (what I'm thinking here on the question: return PartCount, true)

Note: I respect that many ROBLOX built-in functions return multiple values, and I argue that they're custom functions made by ROBLOX, and they're mostly coded in C++, so... ye

1 answer

Log in to vote
0
Answered by
PolyyDev 214 Moderation Voter
5 years ago

Yes you can do that. Example:

function numx2(x)
    return x,x*2
end
local orig,x2 = numx2(8)

print(orig,x2) --> 8 16

Sorry for the weird example just thinking off the top of my head.

Ad

Answer this question