Grim 1 function arguments
Posted: Fri Mar 01, 2019 6:57 pm
In Grim 1, I was having trouble passing arguments to functions in another script so I placed a small script in a test dungeon I created for such purposes. I found that as long as the function I was passing the argument to was in the same script everything worked fine but if the receiving function was in a different script in would not work. I seems the argument gets passed as a table.
I could understand this if I was passing an array or table, but I would think that a string or number value would get passed as a string or number. Needless to say, in the receiving function 'pt(a)', the error -attempting to perform arithmetic on a table value- is generated in the second line. Can anyone tell me why arguments get passed as a table when calling a function in another script? What I am doing wrong?
I could understand this if I was passing an array or table, but I would think that a string or number value would get passed as a string or number. Needless to say, in the receiving function 'pt(a)', the error -attempting to perform arithmetic on a table value- is generated in the second line. Can anyone tell me why arguments get passed as a table when calling a function in another script? What I am doing wrong?
Code: Select all
function argTest() --main function
local n = 10
n = pt(n)
print(n) --> (prints 15)
end
function pt(a) --called function
return a + 5
end
But if 'function pt(a)' is placed in another script ( call it 'test_pass' ), it does not work:
function argTest() --main function
local n = 10
n = test_pass:pt(n)
print(n)
end
-- <OTHER SCRIPT> 'test_pass'
function pt(a) --called function in script 'test_pass'
return a + 5 --error generated here
end