Indigo Rose Software
  #1  
Old 04-19-2005
tkilshaw's Avatar
tkilshaw tkilshaw is offline
Indigo Rose Customer
 
Join Date: Apr 2005
Location: Kelowna, BC, Canada
Posts: 17
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
If I quote "true" and "false" the function works but I get a string value and not a boolean value back.

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.
Reply With Quote
  #2  
Old 04-19-2005
tkilshaw's Avatar
tkilshaw tkilshaw is offline
Indigo Rose Customer
 
Join Date: Apr 2005
Location: Kelowna, BC, Canada
Posts: 17
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
Reply With Quote
  #3  
Old 04-19-2005
Sergio_S Sergio_S is offline
Indigo Rose Customer
 
Join Date: Oct 2003
Location: Sao Paulo, Brazil
Posts: 128
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.
Reply With Quote
  #4  
Old 04-19-2005
Sergio_S Sergio_S is offline
Indigo Rose Customer
 
Join Date: Oct 2003
Location: Sao Paulo, Brazil
Posts: 128
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software