PDA

View Full Version : Handling Return Values



bloodylemming
December 24th, 2021, 23:19
Trying to figure out how to get a return value from a function, so I can do stuff with it.

Here's my test function:

function addThis(a, b)
Debug.chat("The sum is ")
return (a + b)
end

The call...

function onValueChanged()
local x = charManager.addThis(1, 25)
Debug.chat(x)
end

I just get an error and none of my debug info is printed...
Tried it all local, from within the onValueChanged function (minus the charManager pointer) and it worked fine...

I don't know what I'm missing...

Moon Wizard
December 25th, 2021, 00:37
Where is your test function defined? Is it in an extension using a script tag with "charManager" (exactly) as the name? (i.e. <script name="charManager" file="..." /> )

Regards,
JPG

bloodylemming
December 25th, 2021, 00:44
Where is your test function defined? Is it in an extension using a script tag with "charManager" (exactly) as the name? (i.e. <script name="charManager" file="..." /> )

Regards,
JPG

Yes, it's in a script file named charManager.lua. Here's the entry under base.xml
<script name="charManager" file="campaign/scripts/charManager.lua" />

I have other functions in there, which are executing just fine.

Trenloe
December 25th, 2021, 04:04
I just get an error and none of my debug info is printed...
When you get an error please report the *exact* error message - this will help with identifying the issue.

bloodylemming
December 25th, 2021, 04:21
When you get an error please report the *exact* error message - this will help with identifying the issue.

Strange. It's working now. Maybe the reboot helped clear something...