User Tag List

Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 35

Thread: Checking for integers and floats....

  1. #1
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    33
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,295
    Level
    24
    vBActivity - Bars
    Lv. Percent
    47.05%

    Checking for integers and floats....

    One final question from me! And please, don't ask me why I made a new thread...

    Okay, in my Cane of Somaria script, I've declared a variable called "SomariaCheck". Every time you change the settings of the combo two tiles away from you, a 1 is written to this variable. At the beginning of the script, it first checks for the solidity of the combo at the Block's position. If it comes back as 15 (in decimal- That'd be 1111 in binary, which is total solidity), it then checks the value of SomariaCheck. If it's a 1, it modifies the block to remove it and it then sets SomariaCheck to 0. The problem is, since I need to use that at the start of my script so it doesn't destroy a block right after I create one, I needed to declare that variable at runtime. Unfortunately, it seems to ignore that value. When I declare a variable in void run(), does it automatically set it to 0? If so, what can I do to avoid this? Telling me to not use another variable isn't going to work- I declare 4 variables at runtime- SomariaBlockX, SomariaBlockY, SomariaBlockPosition, and SomariaCheck. The first two are because I don't need to write anything to them at first. The second two are there because I use them both in the code for checking for a block. So, what's going on? Do those variables simply become 0 whenever the code ends? Would writing to d0-7 be better?

  2. #2
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,451
    Level
    24
    vBActivity - Bars
    Lv. Percent
    73.19%

    Re: Checking for integers and floats....

    If it comes back as 15 (in decimal- That'd be 1111 in binary, which is total solidity), it then checks the value of SomariaCheck. If it's a 1, it modifies the block to remove it and it then sets SomariaCheck to 0. The problem is, since I need to use that at the start of my script so it doesn't destroy a block right after I create one, I needed to declare that variable at runtime.
    Technically, you're declaring them well before run time.
    If you only need two different values, corresponding roughly to "yes" and "no," you might use a bool instead of a number. A bit more logical, and easier to change: you can just write SomariaCheck = !SomariaCheck; instead of going through an if/else or an equation. That's not too important, though.

    When I declare a variable in void run(), does it automatically set it to 0? If so, what can I do to avoid this?
    I don't know if it does, actually, but I don't see why it would matter. Not unless you're planning to use an uninitialized variable for something, which is pretty much never a good idea.
    If you're just trying to set the starting value, initialize it when you declare it, like this:
    Code:
    int x = 5;
    So, what's going on? Do those variables simply become 0 whenever the code ends? Would writing to d0-7 be better?
    Don't know. Probably not. But what difference does it make? If it's finished with the code, you can't use the variables anymore, anyway.
    You can't use d0-d7. There's no way to access them directly in ZScript.

  3. #3
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    33
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,295
    Level
    24
    vBActivity - Bars
    Lv. Percent
    47.05%

    Re: Checking for integers and floats....

    Quote Originally Posted by Saffith View Post
    Technically, you're declaring them well before run time.
    If you only need two different values, corresponding roughly to "yes" and "no," you might use a bool instead of a number. A bit more logical, and easier to change: you can just write SomariaCheck = !SomariaCheck; instead of going through an if/else or an equation. That's not too important, though.

    I don't know if it does, actually, but I don't see why it would matter. Not unless you're planning to use an uninitialized variable for something, which is pretty much never a good idea.
    If you're just trying to set the starting value, initialize it when you declare it, like this:
    Code:
    int x = 5;
    Don't know. Probably not. But what difference does it make? If it's finished with the code, you can't use the variables anymore, anyway.
    You can't use d0-d7. There's no way to access them directly in ZScript.
    It figures. :p

    So what exactly does SomariaCheck = !SomariaCheck; do, anyways? But wouldn't I still need to do an if statement? It's supposed to do one thing if it's equal to a certain thing and not do that if it's not equal. ...Oh well. You understand this more than me. :p

  4. #4
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,451
    Level
    24
    vBActivity - Bars
    Lv. Percent
    73.19%

    Re: Checking for integers and floats....

    Well, I'm assuming it's a bool there. Bools can be either true or false. The exclamation point is the NOT operator: !true is false, and !false is true. So, if SomariaCheck is a bool, that line has the same effect as this:
    Code:
    if(SomariaCheck == true) // You could also just write if(SomariaCheck)
       SomariaCheck = false;
    else
       SomariaCheck = true;
    That's only if it's a bool, though. You can't do that with numbers.

  5. #5
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    33
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,295
    Level
    24
    vBActivity - Bars
    Lv. Percent
    47.05%

    Re: Checking for integers and floats....

    So, let's say I was to do something like Link->InputUp = true. If I used SomariaCheck = !SomariaCheck, would it look like this:

    Code:
    SomariaCheck = !SomariaCheck;
    Link->InputUp = true;
    Or would I use something else? (Please bear with me- I'll remember this for a while once I get it, trust me.)

  6. #6
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,451
    Level
    24
    vBActivity - Bars
    Lv. Percent
    73.19%

    Re: Checking for integers and floats....

    I'm not certain I see what you're asking, but that bit of code looks perfectly fine.

  7. #7
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    33
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,295
    Level
    24
    vBActivity - Bars
    Lv. Percent
    47.05%

    Re: Checking for integers and floats....

    Quote Originally Posted by Saffith View Post
    I'm not certain I see what you're asking, but that bit of code looks perfectly fine.
    Let me put it another way... If I was to use SomariaCheck as a bool instead of a number, at places I'd normally use if/else statements for numbers, I'd use SomariaCheck = !SomariaCheck instead of if (SomariaCheck = 1)?

  8. #8
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,451
    Level
    24
    vBActivity - Bars
    Lv. Percent
    73.19%

    Re: Checking for integers and floats....

    SomariaCheck = !SomariaCheck will change the value from true to false or from false to true. It won't do anything else that would otherwise require an if/else.
    Code:
    SomariaCheck = !SomariaCheck;
    Link->InputUp = true;
    is equivalent to
    Code:
    if(SomariaCheck == true)
       SomariaCheck = false;
    else
       SomariaCheck = true;
    
    Link->InputUp = true;

  9. #9
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    33
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,295
    Level
    24
    vBActivity - Bars
    Lv. Percent
    47.05%

    Re: Checking for integers and floats....

    Quote Originally Posted by Saffith View Post
    SomariaCheck = !SomariaCheck will change the value from true to false or from false to true. It won't do anything else that would otherwise require an if/else.
    Code:
    SomariaCheck = !SomariaCheck;
    Link->InputUp = true;
    is equivalent to
    Code:
    if(SomariaCheck == true)
       SomariaCheck = false;
    else
       SomariaCheck = true;
    
    Link->InputUp = true;
    ....Okay, then that's not exactly what I need. Here's the basic excerpt of code that does all that for only letting one block on screen at a time:

    Code:
    if (SomariaCheck ==1)
    		{
    			if (Screen->ComboS [SomariaBlockPosition] == 15)
    			{
    				Screen->ComboD [SomariaBlockPosition] = CmbR;
    				Screen->ComboC [SomariaBlockPosition] = CmbRC;
    				Screen->ComboT [SomariaBlockPosition] = CmbRT;
    				Screen->ComboF [SomariaBlockPosition] = CmbRS;
    				Screen->ComboI [SomariaBlockPosition] = CmbRI;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    				SomariaCheck = 0;
    			}
    		}
    It first checks for the value of SomariaCheck, and if that's 0, it checks for solidity at the value of SomariaBlockPosition. You could say I only need the check, but I have both as a sort of failsafe, just in case something goes a bit wrong. See, your bool thing won't work because I'm not JUST changing the value of SomariaCheck. In fact, I don't have to do that at all. I'm only doing it because it makes sense that if I was using 1 for "A Block is on the Screen" that 0 should be used when a block ISN'T on the screen. Just common sense, I guess. Anyways, it modifies EVERYTHING about the block's combo and stuff so it's back to being normal, average ground. Do you understand?

  10. #10
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,451
    Level
    24
    vBActivity - Bars
    Lv. Percent
    73.19%

    Re: Checking for integers and floats....

    Yeah. In that case, it won't save you any time.

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