Indigo Rose Software
Indigo Rose Software
Log in to the Customer Portal Customer Login
Software Development Discussion Forums Forums
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    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 04:38 PM.

  2. #2
    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

  3. #3
    Join Date
    Oct 2003
    Location
    Sao Paulo, Brazil
    Posts
    141
    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 07:44 PM.

  4. #4
    Join Date
    Oct 2003
    Location
    Sao Paulo, Brazil
    Posts
    141
    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

Similar Threads

  1. Programming in Lua - "...the beginning"
    By Intrigued in forum Developer's Den
    Replies: 5
    Last Post: 08-06-2006, 06:31 AM
  2. Create and Print XML or HTM
    By markstaylor in forum AutoPlay Media Studio 5.0
    Replies: 7
    Last Post: 10-26-2004, 06:00 AM
  3. Function: Blowfish Encrypt/Decrypt Strings
    By Lorne in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 05-31-2004, 03:16 PM
  4. Function: Resize & Center an Image
    By kpsmith in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 05-17-2004, 01:36 PM
  5. Function: Convert boolean value to string
    By Desmond in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 05-07-2004, 01:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Indigo Rose Software