Help with Boolean and INI files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • T3STY
    Forum Member
    • Feb 2009
    • 1289

    Help with Boolean and INI files

    Hi! It' s me again! ;D
    This time I need help with some boolean values.
    In my project I have 12 Buttons. I want to set visible and enabled values in every table by using some INI values. So it might be like this (only one button here but it' s the same for all 12, changes only the table name and the ini section name):

    Code:
    Enabled = INIFile.GetValue(_SourceFolder.."\\ButtonSettings.ini", "BUTTON1", "ENABLED");
    Visible = INIFile.GetValue(_SourceFolder.."\\ButtonSettings.ini", "BUTTON1", "VISIBILE");
    
    tblBtnProps = {};
    tblBtnProps.Enabled = Accessibile;
    tblBtnProps.Visible = Visibile;
    
    Button.SetProperties("Button1", tblBtnProps);
    and the INI file (ButtonSettings.ini) has this values:

    Code:
    [BUTTON1]
    ENABLED=False
    VISIBLE=true
    Here is the problem because, even if 'enabled' value in the ini is set to "false" or the 'visible' value is set to "false", nothing happens. The button doesn' t become disabled or invisible.

    Anyone know why? Is this a "bug" of AMS ?
  • Imagine Programming
    Indigo Rose Customer
    • Apr 2007
    • 4252

    #2
    You get values from an ini file as a string, not as boolean. So you need to check if it's "true" or "false" instead of the boolean values true or false.

    example:
    Code:
    Enabled = INIFile.GetValue(_SourceFolder.."\\ButtonSettings.ini", "BUTTON1", "ENABLED");
    Visible = INIFile.GetValue(_SourceFolder.."\\ButtonSettings.ini", "BUTTON1", "VISIBILE");
    
    if(Enabled=="true")then 
        Button.SetEnabled("Button1", true); 
    else
        Button.SetEnabled("Button1", false); 
    end
    if(Visible=="true")then
        Button.SetVisible("Button1", true); 
    else
        Button.SetVisible("Button1", false); 
    end
    Bas Groothedde
    Imagine Programming :: Blog

    AMS8 Plugins
    IMXLH Compiler

    Comment

    • T3STY
      Forum Member
      • Feb 2009
      • 1289

      #3
      Thanks, it works!

      But, I have a question: why doesn't AMS get the value as boolean? The string in the INI and the boolean are the same word so, in theory, it could get it as boolean..

      Comment

      • Imagine Programming
        Indigo Rose Customer
        • Apr 2007
        • 4252

        #4
        Originally posted by T3STY View Post
        Thanks, it works!

        But, I have a question: why doesn't AMS get the value as boolean? The string in the INI and the boolean are the same word so, in theory, it could get it as boolean..
        Well no, it doesn't matter if the word is the same, it's the type of variable that matters.

        true and false are only in you're source and of type boolean. It could be done with a loadstring(), but that's running a lua string < so yet again. A string.

        the true and false you've got in your ini file, basicly have "" around it just as you type a filepath string in the code editor. so it's a string, not boolean
        Bas Groothedde
        Imagine Programming :: Blog

        AMS8 Plugins
        IMXLH Compiler

        Comment

        • T3STY
          Forum Member
          • Feb 2009
          • 1289

          #5
          OK, I understand now. Tankyou, bye!

          Comment

          Working...
          X