Starter1 Posted July 6, 2022 Posted July 6, 2022 I got a number in one function, how to pass this number to another function(for example: function ONE() a=2 end function TWO() 'here we need to pass the value a' end
MAARS Posted July 9, 2022 Posted July 9, 2022 you have multiple way to acomplish this. 1. you can declare the variable outside of a function so you can access it everywhere local a = 10 local function foo () print (a) -- 10 end local function bar () print (a) -- 10 end bar() 2. you can use the return statement inside a function to pass a value local function foo () local a = 10 return a end local function bar () local a = foo() print (a) -- 10 end bar() 3. In your code you have declared the variable a as a global since you did not use the local keyword. in this case once you run your function one time the variable a will be avalaible averywhere in the script local function foo() a = 10 end foo() local function bar() print (a) -- 10 end bar()
Question
Starter1
I got a number in one function, how to pass this number to another function(for example:
function ONE()
a=2
end
function TWO()
'here we need to pass the value a'
end
1 answer to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.