Function Return Value Problem
JonathanD
10 Apr 2004, 13:48Hello. I'm having a problem returning values from functions. Functions that I write without conditionals work properly, but functions that contain conditionals (at least with variables and/or math/comparisons in the parameters) are not returning values for me. Here are two functions that simply return empty or null strings:
All of the variables are set and valid. Correct spelling everywhere. Does anyone have any advice for me?
define function <CheckSpendingLimit>
{
set numeric <tmpTotalSpent; %CategorySpent% + %ToRaise%>
if ( %tmpTotalSpent% > %SpendingLimit% ) then return <FALSE> else return <TRUE>
}
end define
define function <CheckSkillMaximum>
{
set numeric <tmpSkillTotal; %SkillLevel% + %ToRaise%>
if ( %tmpSkillTotal% > %SkillMax% ) then set string <ReturnValue; FALSE> else set string <ReturnValue; TRUE>
return <#ReturnValue#>
}
end define
All of the variables are set and valid. Correct spelling everywhere. Does anyone have any advice for me?
Arbutus
21 Jun 2006, 17:44I'm experiencing the same problem. As a work-around, I was using the conditional statements to set a variable and returning that variable at the end of the function. But now it seems my function will only return a value if the return is the only code in the function! Still testing...
MaDbRiT
21 Jun 2006, 22:27Hi guys
Jonathan D wrote, and Artubus concurred that the following function (by way of example) doesn't work...
Well this clearly isn't going to work - what are those curly braces (at top and bottom of the function) doing in there? Quest ASL isn't like C++ (thank goodness!) and so you don't need to put the body of a function inside curly braces.
As it is, they're confusing the interpreter, leave them out and the function works fine (and yes I have tested it).
Al
Jonathan D wrote, and Artubus concurred that the following function (by way of example) doesn't work...
define function <CheckSkillMaximum>
{
set numeric <tmpSkillTotal; %SkillLevel% + %ToRaise%>
if ( %tmpSkillTotal% > %SkillMax% ) then set string <ReturnValue; FALSE> else set string <ReturnValue; TRUE>
return <#ReturnValue#>
}
end define
Well this clearly isn't going to work - what are those curly braces (at top and bottom of the function) doing in there? Quest ASL isn't like C++ (thank goodness!) and so you don't need to put the body of a function inside curly braces.
As it is, they're confusing the interpreter, leave them out and the function works fine (and yes I have tested it).
Al
Arbutus
21 Jun 2006, 22:43Brilliant! I wasn't having a problem with the same code but that's the answer. The problem is that QDK is generating those curly braces.
I add a function and the code produced is:
When I add a conditional statement, the code saved by QDK becomes:
The braces can be removed from the code manually, but they will return next time you change that function's code in QDK. Add that to the bug list.
I add a function and the code produced is:
define function <myfunction>
return <%i%>
end define
When I add a conditional statement, the code saved by QDK becomes:
define function <myfunction>
{
if ( %i% = 5 ) then msg <weird, huh?>
return <%i%>
}
end define
The braces can be removed from the code manually, but they will return next time you change that function's code in QDK. Add that to the bug list.
paul_one
22 Jun 2006, 08:28Ouch... That is quite bizare!
*oh how bizare, how bizare!*
(Only people over 25 should get that)
But yeah, setting a variable is the only way to return a proper value from a function..
I use it for detecting errors.
*oh how bizare, how bizare!*
(Only people over 25 should get that)
But yeah, setting a variable is the only way to return a proper value from a function..
I use it for detecting errors.
MaDbRiT
22 Jun 2006, 08:34Arbutus wrote
Now that is truly wacky! I must admit to not using QDK and I tend to forget that other people do use it
That being the case, it is something Alex needs to take a look at - but I suspect one can work-around the problem by putting manually written / fixed functions into a seperate library and then including them within QDK.
I haven't tried that myself, but I see no reason why it would not work (and QDK would not alter the definitions in the library).
Al
The problem is that QDK is generating those curly braces.
Now that is truly wacky! I must admit to not using QDK and I tend to forget that other people do use it

That being the case, it is something Alex needs to take a look at - but I suspect one can work-around the problem by putting manually written / fixed functions into a seperate library and then including them within QDK.
I haven't tried that myself, but I see no reason why it would not work (and QDK would not alter the definitions in the library).
Al
Overcat
22 Jun 2006, 22:26Hey, this is me. That is, JonathanD is me, Overcat. Perhaps this username, JonathanD should be deleted (I don't know if that would destroy posts) or made inactive. 
