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

Returning a value without ending the function?

Asked by
Muoshuu 580 Moderation Voter
9 years ago

Is it possible to run a function and return a value while code is still being executed within? If so, how would I go about doing so?

0
Happy 100 rep milestone(; Goulstem 8144 — 9y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Technically speaking, no there isn't any way to use the return statement in a function without discontinuation occurring.


But there is an alternative. You can just define a value before running the function, and have a parameter inside the function which will be set to whatever value you want


Example;

function derp(argument, variableParam)
    --code
    variableParam = 0
    --code
end

local a = 1
derp(argument,a)

Now,'a' will be set to 0 whenever the function derp runs.. so it's kinda like returning a value(:

Ad

Answer this question