User Tag List

Results 1 to 7 of 7

Thread: const bool?

  1. #1
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.73%

    const bool?

    Howcomes we can't have constant bools?

  2. #2
    Keese ScaryBinary's Avatar
    Join Date
    Dec 2006
    Age
    49
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    915
    Level
    10
    vBActivity - Bars
    Lv. Percent
    51.73%

    Re: const bool?

    ...I haven't checked the compiler yet, but I'm assuming that you can't get your script to compile with something like
    Code:
    const bool This_Is_True = true;
    in it?

    You could just use an integer (1 for true, 0 for false) and I think all your logical expressions will work fine. Something like
    Code:
    const int Link_Is_Awesome = 1;
    
    if (Link_Is_Awesome && (Link->HP > 0)) {
      //...do whatever...
    }
    should work.

    Or just use a bool and try to not ever change it....?

    What would you use a constant bool for? An optional game setting or something?

  3. #3
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.73%

    Re: const bool?

    Well yes, I could use an integer, but it just looks a bit messy. And that if would give me a 'Cast from float to bool' warning every time I run it through the compiler, which isn't the end of the world, but it's quite annoying.

    I've just gone with a bool that I'm not gonna change.
    It's just for ease of reading really, I have some solidity checks which are generalised for left/right and for up/down, so they need to have a bool to tell the script which one to check.
    Code:
    bool soliditycheck(int x, int y, bool horizvert){
     if(horizvert){
      //check for up down
     }else{
      //check for left right
      }
    }

  4. #4
    Octorok CaRmAgE's Avatar
    Join Date
    Oct 2008
    Location
    Historia
    Age
    35
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,335
    Level
    12
    vBActivity - Bars
    Lv. Percent
    42.82%

    Re: const bool?

    This is probably because the developers didn't think anyone would need a constant boolean declaration, since you can simply tack true or false into a conditional statement or argument list for a function. For example, ScaryBinary's

    Code:
    const int Link_Is_Awesome = 1;
    
    if (Link_Is_Awesome && (Link->HP > 0)) {
      //...do whatever...
    }
    would become

    Code:
    if (true && (Link->HP > 0)) {
      //...do whatever...
    }
    I do agree, however, that such declarations should be allowed for ease of reading.

    And, yes, integers work, since a boolean is simply a special type of integer, and it isn't as messy as you think. You only need to change the declaration of your variables: the conditional statement does not need to be changed at all. So, in your example...

    Code:
    bool soliditycheck(int x, int y, int horizvert){
     if(horizvert){
      //check for up down
     }else{
      //check for left right
      }
    }
    Does this make sense? I'm sorry if I'm confusing you.

  5. #5
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.73%

    Re: const bool?

    Code:
    bool soliditycheck(int x, int y, int horizvert){
     if(horizvert){
      //check for up down
     }else{
      //check for left right
      }
    }
    The 'if(horizvert)' line would cause the compiler to give me a 'Cast from float to bool' error every time I compiled it.
    I'd have to use 'if(horizvert==1)', and I don't really want to

    I understand it, I was just wondering if there was any reason for it.

  6. #6
    Octorok CaRmAgE's Avatar
    Join Date
    Oct 2008
    Location
    Historia
    Age
    35
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,335
    Level
    12
    vBActivity - Bars
    Lv. Percent
    42.82%

    Re: const bool?

    Wow. A boolean isn't considered a type of integer in ZScript? How odd.

    Well, whatever you think is best. This thing is starting to sound like a bug to me, so I'd say post something in the Open Beta Bugs forum to let the ZC developers know about the compiler error.

  7. #7
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.73%

    Re: const bool?

    There are no true integers in ZScript.
    All integers are actually floats.

    If you look in std.zh (the header file containing the pre-set constants), there's a line that says 'const int PI = 3.142;'

    It's not really a bug, I'm assuming they missed this out on purpose, I was just wondering why.
    You don't get a compile error for writing that, just a warning.

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
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social