|
#1
|
||||
|
||||
|
Lua Boolean function return problem
My attempts to build a function that returns a boolean value have failed.
This fails with an error on the line that includes the return statement. Code:
function isCheese( food )
if food == "cheese" then
return true;
else
return false;
end
end
Lua defines true and false as keywords. Am I doing something wrong or does Lua just not support returning booleans? thanks, Terry Last edited by tkilshaw; 04-19-2005 at 05:38 PM. |
|
#2
|
||||
|
||||
|
The problem was not in the function but in my attempt to use its return value in Dialog.Message.
The error message given was valid, but the line number for the error was not. It said the error was in the On Startup script (Correct) but gave a line number of 8. At that point there were only 2 lines in the On Startup script. When I edited the called function to add an extra line, the error line number went up by one. Terry |
|
#3
|
|||
|
|||
|
Once I saw in a code that instead of true and false, you may return 1 (for true) and nil (for false) and even skip the whole part of else, that the end of the function will return nil.
Try it. Sergio Last edited by Sergio_S; 04-19-2005 at 08:44 PM. |
|
#4
|
|||
|
|||
|
Additionally, depending on the version of Lua, only nil makes a condition false or, in the version 5.0, both nil and false make a condition false. Any other value (even 0 and "") makes it true.
So, maybe you can try also: Code:
function isCheese( food )
if food == "cheese" then
return true;
end
end
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming in Lua - "...the beginning" | Intrigued | Developer's Den | 5 | 08-06-2006 07:31 AM |
| Create and Print XML or HTM | markstaylor | AutoPlay Media Studio 5.0 | 7 | 10-26-2004 07:00 AM |
| Function: Blowfish Encrypt/Decrypt Strings | Lorne | AutoPlay Media Studio 5.0 Examples | 0 | 05-31-2004 04:16 PM |
| Function: Resize & Center an Image | kpsmith | AutoPlay Media Studio 5.0 Examples | 0 | 05-17-2004 02:36 PM |
| Function: Convert boolean value to string | Desmond | AutoPlay Media Studio 5.0 Examples | 0 | 05-07-2004 02:14 PM |
All times are GMT -6. The time now is 09:07 PM.








Linear Mode

