Results 1 to 20 of 20

Thread: are booleans set false as default?

  1. #1
    Join Date
    Oct 2012
    Location
    Porto, Portugal
    Posts
    218
    Mentioned
    0 Post(s)
    Quoted
    42 Post(s)

    Default are booleans set false as default?

    When I use a boolean is it set False as default? Or is it True?
    To set the boolean to False or True I do this

    Simba Code:
    Boolean := True/False

    But if I just use it without seting it? Is it False or True by default?

  2. #2
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    I believe they retain a null statement, meaning neither true or false when initally called upon. (declaring it)

  3. #3
    Join Date
    Dec 2011
    Location
    Holland
    Posts
    545
    Mentioned
    0 Post(s)
    Quoted
    19 Post(s)

    Default

    Simba Code:
    program new;
    var v: Boolean;
    begin
      if v then
        writeln('v is true.')
      else
        writeln('v is false.');
    end.

    Progress Report:
    v is false.

  4. #4
    Join Date
    Oct 2012
    Location
    Porto, Portugal
    Posts
    218
    Mentioned
    0 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by Shay View Post
    I believe they retain a null statement, meaning neither true or false when initally called upon. (declaring it)
    so in the start of the procedure I have to set it to False so that if the procedure fails it returns false right?

  5. #5
    Join Date
    Oct 2012
    Location
    Porto, Portugal
    Posts
    218
    Mentioned
    0 Post(s)
    Quoted
    42 Post(s)

    Default

    on a complete off-topic question. is there a procedure in includes to select options like this:


  6. #6
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by Nirvana View Post
    so in the start of the procedure I have to set it to False so that if the procedure fails it returns false right?
    Booleans are false by default, integers are 0 by default, strings are empty by default.
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

  7. #7
    Join Date
    Oct 2012
    Location
    Porto, Portugal
    Posts
    218
    Mentioned
    0 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by euphemism View Post
    Booleans are false by default, integers are 0 by default, strings are empty by default.
    Thanks. What about the other non related question?

  8. #8
    Join Date
    Apr 2012
    Posts
    127
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Nirvana View Post
    on a complete off-topic question. is there a procedure in includes to select options like this:

    TypeSendEx('1', False); will select option 1
    TypeSendEx('2', False); will select option 2
    Feel free to add me on msn: h4x_new@hotmail.co.uk
    Delete my old msn that got hacked (h4x_@hotmail.co.uk)

  9. #9
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Ah, that's interesting to know!

    FindNPCChatText(); will do it.

  10. #10
    Join Date
    Oct 2012
    Location
    Porto, Portugal
    Posts
    218
    Mentioned
    0 Post(s)
    Quoted
    42 Post(s)

    Default

    thanks.

  11. #11
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    A Boolean is simply an one or a zero. There is no null. Null is often used for object, like a TBitmap, where it is null because the object doesn't exist. Note that in some languages the memory space for a Boolean doesn't exist when you declare it, in that case you will have to set it. In simba you can set it to false at the start of you procedure or function, not for usefulness but for readability of the code.
    Working on: Tithe Farmer

  12. #12
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Booleans are set to false on call, but there once was a bug in SRL which turned out to be an integer who did not reset after the procedure where the integer was declared internally didn't reset. Basically; in Pascal Script you can't be 100% sure it's always at False state upon declaration without setting it to false yourself, even though it should have been set to false.

  13. #13
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Zyt3x is right...
    I've always thought that it's only for readability but in PS...
    Simba Code:
    program new;
    function TrueByDefault: Boolean;
    begin
    //Result:= False;
    end;

    begin
      while not TrueByDefault do
        wait(100);

      writeln('We break out of an infinite loop! Time to switch to la-pe!');
    end.

    I got stuck for 15min today figuring out why a loop in my script ended prematurely...and i remembered this and sure enough, that bug is the cause of error.

    Does that mean we should set other results (string, integer, arrays etc) to null/0 manually upon function entry as well?


    EDIT: hmm could be a Simba bug actually... i ran it on a new Simba and it worked as expected, but on the original Simba...



    Switching to la-pe (on the same bugged Simba) immediately fixed the problem.

  14. #14
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    What? Your code is named badly..

    While Not FalseByDefault..


    This will run infinitely because Not false is true..

    A conditional statement/loop will run as long as the condition is true. This behaviour is perfectly normal. AFAIK, all languages set booleans to false by default.

    Never heard of such a bug and I don't think such a bug would or did exist because by default, everything is set to off. You have to set it to >= 1 to turn it on. Computers read in binary. 1's and 0's. It will never start at one.

    If such a bug did exist, someone programmed badly. I run your code and it works for me but my Simba is old.
    Last edited by Brandon; 11-23-2012 at 02:20 AM.
    I am Ggzz..
    Hackintosher

  15. #15
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Yes, it should be false by default, but it ended up as true by default instead, as demonstrated in my screenshot above. (the loop breaks out and debug is shown)

    I think it could be a Simba bug though, as opening a new Simba fixed the problem.

  16. #16
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Simba has nothing to do with the code tbh; it is pascal script that is failing to address "new" variables correctly. The Interpreter is doing all the script work.

    Moral of the story; Use la-pe or declare everything yourself.

  17. #17
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    Simba has nothing to do with the code tbh; it is pascal script that is failing to address "new" variables correctly. The Interpreter is doing all the script work.

    Moral of the story; Use la-pe or declare everything yourself.

    Too buggy. Takes FOREVER to compile. XOR doesn't work 100% of the time. AddOnTerminate doesn't work.

    Simba Code:
    var
      BMP: Integer;

    {$I SRL/SRL.Simba}

    Procedure FreeBMP;
    Begin
      FreeBitmap(BMP);
    End;

    begin
        Bmp := BitmapFromString(25, 23, 'meJxtlYtWm0AQhl+rrdZ7buQCJN' +
            'Fa7StVE2C56jNYE5ZdEu2z9Z8dQDA95zs5hLP75Z+ZDej0p2aSO3z' +
            'usw922U2ZXutkqeJFEc0ZGboycpgidlXk6Ngtk/k+W7KnzO6Yt6e7' +
            '96cfb9nNPr3eJcsyXuhoTphdbXCHiOZYg5W0uJYAJPn7fMuqxqNCl' +
            'zjwIAlgScXT/fvzL4A8VBQbTIYitDsBCLuhTJxPKlPUPUnSW3SmSm' +
            'I8TFtltnfYpQtsIaBNb1nC7UUtbJBiVnvs1ka3De60ArswNDOSJgw' +
            'k7GFVI9ln84baY3d6yIOOacR5XVTdpVmTpOPJnDK1VTwtwin/rhQT' +
            'wJ4isYGMZ91Z2/8vKpmRJ5rIcJwHYMoqHDk6aaljsA9m9AHdbEnII' +
            'yyjqmhUOnNBteUAFNuWyMj6sLFQWPx3UMlcpwtW7WrKZKbjKVDRBB' +
            'ShJcUoD4Zbf7ANerhokPCEY/LgDBgVdaPxUJjKQ8u6HlKJPsBXoxp' +
            'hDR+GMlvuiTmH4TyfJJWnxadUVFddWpl2kmCBpD50JBuv31aZPOTB' +
            'Fm5p008VjXVoKSwIhkD6Ayb3+kB6Q6bwR0AFFreRA1Tzjc1cxEiFg' +
            '0L0ZdBrtpPBXJPTSMgQWFqMAXej7gm0aP6QckZDSFRwVfiXcl1ReF' +
            'fK73E29mgxKcNpResQVoMQVxiKNBLyeBf5+jxfXRyqKImR7KKZxj+' +
            'rpSoEGfLgfOtdbLzT18fjzer7dn2Se6ewwckq9A0N5NJUMKZgwi4j' +
            'F/BjEE+brX8GA0nWJzA0Humfkce/hEcHfVZxf+ABu9DRoVM/x0i1W' +
            'R2/Ph4BXIDcO5E+eYrgvCo26GEQrOKhq3AKqDqOZJ7teBe8PHx5+f' +
            '31z8O37eNRvjo2nlN4lDCR0D14jApzqeZed8lQefA6+AcVQ5qj');

      AddOnTerminate('FreeBMP');   //Leaks the bitmap.. OutOfMemory exception is thrown when ran too much..
      //When testing scripts over and over, memory builds up, you need to restart simba/smart and continue where you left off.
      //if you do SetupSRL, even worse.
    end.
    Last edited by Brandon; 11-23-2012 at 01:59 PM.
    I am Ggzz..
    Hackintosher

  18. #18
    Join Date
    Jul 2011
    Location
    /home/litoris
    Posts
    2,226
    Mentioned
    0 Post(s)
    Quoted
    159 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Too buggy. Takes forever to compile. XOR doesn't work 100% of the time.
    You can make you own xor using and's and not's right?
    Miner & Urn Crafter & 07 Chicken Killer
    SPS BlindWalk Tutorial

    Working on: Nothing

    teacher in every art, brought the fire that hath proved to mortals a means to mighty ends

  19. #19
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by litoris View Post
    You can make you own xor using and's and not's right?
    With If statements yeah.
    I am Ggzz..
    Hackintosher

  20. #20
    Join Date
    Dec 2011
    Location
    Holland
    Posts
    545
    Mentioned
    0 Post(s)
    Quoted
    19 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    With If statements yeah.
    Simba Code:
    function cXor(a, b: boolean): boolean;
    begin
      result := (a and not b) or (not a and b);
    end;

    or

    Simba Code:
    function cXor(a, b: boolean): boolean;
    begin
      result := (a or b) and not (a and b);
    end;
    ^ a or b, and not a and b. basically the definition of xor ^.^

    Can't test it on phone, but this should work

    Edit: procedure -> function ofc xD
    Last edited by Chris; 11-28-2012 at 10:51 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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