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

How to update a Module Variable?

Asked by 9 years ago

How to update a Module Variable? explanation below

--module script
module={}

pose = "idle"

module.one = function()
print(pose)
if pose == "walk" then
--do stuff and
module.two()
end
end

module.two= function()
if pose == "walk" then
--do stuff and
module.one()
end
end
return module
--Local script
--require stuff so S = module script
S.pose = "walk" --So I change the variable first, then call the function
S.one()  --but the function says pose == idle when I just changed it .-.

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Careful.

Your ModuleScript doesn't ask for module.pose. It just has pose as a global variable.

If you want to be able to modify it from the outside, you should use instead refer to module.pose within the ModuleScript (which the other scripts can touch as in S.pose)


Nonetheless, I think it would be better to pass the pose as a parameter to a function, rather than modifying the variable directly.

0
Thank you so much! Worked like a charm! Orlando777 315 — 9y
Ad

Answer this question