User Tag List

Page 2 of 4 FirstFirst 1 2 3 4 LastLast
Results 11 to 20 of 35

Thread: Checking for integers and floats....

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

    Re: Checking for integers and floats....

    Quote Originally Posted by Saffith View Post
    Yeah. In that case, it won't save you any time.
    So, do you think you can figure out what's wrong with my script? It doesn't seem to erase the block that's already on-screen, even though it's supposed to set SomariaCheck to 1 at the end of the script... Sigh... Do you think I should post the entire script here so you can see if I did anything wrong on it? Oh, and by the way, why is it that you can't declare the same variable twice? I'm thinking my problem might be that I don't put int at the end of the script where I put SomariaCheck = 1;. Could that be it?

  2. #12
    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,433
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.08%

    Re: Checking for integers and floats....

    Yeah, probably best to post the whole thing. Can't see anything wrong with what's been posted so far.

    Oh, and by the way, why is it that you can't declare the same variable twice?
    Well, basically, declaring a variable creates a new variable without any regard for existing ones. If you try to declare a variable a second time, it'll think you're trying to create a new variable with the same name. That would be a problem, obviously, since you would have to refer to them the same way and it would never know which you meant.
    It could be changed to allow multiple declarations, but there's really no advantage to that. If anything, it would just make code redundant and more confusing.

    I'm thinking my problem might be that I don't put int at the end of the script where I put SomariaCheck = 1;. Could that be it?
    Very unlikely. If it compiles as it is, even if it doesn't work right, it's definitely not that.

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

    Re: Checking for integers and floats....

    Okay. Here's my code:

    Code:
    // OoA Cane of Somaria- When used, this item will create a block in front of Link if the block in front of him isn't solid. 
    // If the combo is solid, this script does nothing.
    // Variables:
    // Cmb- The combo that the Cane switches a screen's combo to. Simply enter the combo number seen in the combo editor!
    // CmbC- The CSet of the new combo. Only use 0-11 for best results.
    // CmbS- Secret Flag of the new combo.
    // CmbI- Inherent Flag of the new combo.
    // CmbT- Combo type of the new combo.
    // CmbS- Solidity of the new combo. Note: SOLIDITY USES THE BINARY SYSTEM. 1111 is total solidity, which is 15 in decimal.
    // SomariaCheck- A special variable used only for checking if a Somaria Block is already on-screen. Creating a Block
    // sets this Variable to 1. Destroying one sets it to 0. This variable is checked only by one function. DO NOT MESS WITH IT!!!!
    // CmbR- The combo the Block resets to when SomariaCheck is set to 1 when you use this item.
    // CmbRC- CSet the of the reset combo.
    // CmbRT- Cmbo type of the reset combo.
    // CmbRS- Secret Flag of the reset combo.
    // CmbRI- Inherent Flag of the reset combo.
    // CmbRSd- Solidity of the reset combo. Don't mess with this unless you know what you're doing, like with CmbSd.
    
    import "std.zh"
    item script CaneSomaria
    {
    	void run(int SomariaBlockX, int SomariaBlockY, int SomariaCheck, int SomariaBlockPosition)
    	{
    		int Cmb = 2123;
    		int CmbC = 10;
    		int CmbS = 79;
    		int CmbI = 61;
    		int CmbT = 0;
    		int CmbSd = 15;
    		int CmbR = 0;
    		int CmbRC = 2;
    		int CmbRT = 0;
    		int CmbRS = 0;
    		int CmbRI = 0;
    		int CmbRSd = 0;
    		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;
    			}
    		}
    		if (Link->Dir == 0)
    		{
    			int BlockCheckY = Link->Y - 32;
    			int BlockCheckX = Link->X;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if (BlockRmndrY <= 8)
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockY = Link->Y - 32;
    				SomariaBlockX = Link->X;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    		}
    		else if (Link->Dir == 1)
    		{
    			int BlockCheckY = Link->Y + 32;
    			int BlockCheckX = Link->X;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if (BlockRmndrY <= 8)
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockY = Link->Y + 32;
    				SomariaBlockX = Link->X;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    
    		}
    		else if (Link->Dir == 2)
    		{
    			int BlockCheckY = Link->Y;
    			int BlockCheckX = Link->X - 32;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if (BlockRmndrY <= 8)
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockX = Link->X - 32;
    				SomariaBlockY = Link->Y;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    		}
    		else if (Link->Dir == 3)
    		{
    			int BlockCheckY = Link->Y;
    			int BlockCheckX = Link->X + 32;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if ( BlockRmndrY <= 8 )
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockX = Link->X + 32;
    				SomariaBlockY = Link->Y;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    		}
    		SomariaCheck = 1;
    	}
    }
    Hope that helps you understand my predicament. I've been working on this for about 4 or 5 days straight, and I'm so close to perfecting this... I can't just leaveit alone now...

  4. #14
    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,433
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.08%

    Re: Checking for integers and floats....

    Ah, yeah, I see now. There are a few different problems. First, this:
    Code:
    void run(int SomariaBlockX, int SomariaBlockY, int SomariaCheck, int SomariaBlockPosition)
    	{
    If you declare variables there, they will be reset to 0 every time the item is used. If you want them to keep their values, declare them before run(), like this:
    Code:
    item script CaneSomaria
    {
    	int SomariaBlockX = 0;
    	int SomariaBlockY = 0;
    	int SomariaCheck = 0;
    	int SomariaBlockPosition = 0;
    
    	void run()
    	{
    That makes them global variables. they'll only be initialized once; after that, they'll start the script with the same values they ended with last time.
    You'll also want to make those CmbRX variables global, or they'll get reset, too.
    Although as it is, you never actually change their values, y'know.

    However, there'll be a problem with doing this, in this case: SomariaCheck won't be reset when you go to another screen. You'll also need to check which screen and map you're on when the item is used and treat SomariaCheck as 0 if they've changed since last time.
    You can't just use screen variables, since those don't get reset when you leave the screen. If you left and came back, they might be wrong.


    There's also this. This might be a problem, or it might be what you intended. Just in case...
    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;
    			}
    		}
    		if (Link->Dir == 0)
    		{
    That won't alternately create and destroy a block; that'll destroy a block and create a new one every time you use the item. If that's what you meant for it to do, it's fine. Otherwise, you can change it by putting an else before the second if statement or by putting Quit(); after setting SomariaCheck to 0.





    That's still not quite perfect, but it'll definitely be closer, at least.

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

    Re: Checking for integers and floats....

    Quote Originally Posted by Saffith View Post
    Ah, yeah, I see now. There are a few different problems. First, this:
    Code:
    void run(int SomariaBlockX, int SomariaBlockY, int SomariaCheck, int SomariaBlockPosition)
    	{
    If you declare variables there, they will be reset to 0 every time the item is used. If you want them to keep their values, declare them before run(), like this:
    Code:
    item script CaneSomaria
    {
    	int SomariaBlockX = 0;
    	int SomariaBlockY = 0;
    	int SomariaCheck = 0;
    	int SomariaBlockPosition = 0;
    
    	void run()
    	{
    That makes them global variables. they'll only be initialized once; after that, they'll start the script with the same values they ended with last time.
    You'll also want to make those CmbRX variables global, or they'll get reset, too.
    Although as it is, you never actually change their values, y'know.

    However, there'll be a problem with doing this, in this case: SomariaCheck won't be reset when you go to another screen. You'll also need to check which screen and map you're on when the item is used and treat SomariaCheck as 0 if they've changed since last time.
    You can't just use screen variables, since those don't get reset when you leave the screen. If you left and came back, they might be wrong.


    There's also this. This might be a problem, or it might be what you intended. Just in case...
    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;
    			}
    		}
    		if (Link->Dir == 0)
    		{
    That won't alternately create and destroy a block; that'll destroy a block and create a new one every time you use the item. If that's what you meant for it to do, it's fine. Otherwise, you can change it by putting an else before the second if statement or by putting Quit(); after setting SomariaCheck to 0.





    That's still not quite perfect, but it'll definitely be closer, at least.
    Okay. In case you didn't know, the script begins by telling you the item is the OoA Cane of Somaria. In that game, using the Cane when the block was already there removed the block and created a new one. Only in LttP and FSA did the block get destroyed when you used the Cane and required you to use it again to make a new one. Speaking of which, I'm making that next. :p

    Thanks Saffith. I knew I could count on you. I was wondering how to define global variables- Now I don't have to ask. So let's see... Should I use GetCurrScreen as a Global variable or a screen variable...? Let me ask you this:

    I'll make four new variables, CurrScreen, LastScreen, CurrMap, and LastMap. They'll all be global, of course, or that defeats their purpose. At the start of the script, I'll write the current screen number to CurrScreen using GetCurrScreen. At the end of the script, I'll write to LastScreen by "copying" the value of CurrScreen to it. I'll do the same with CurrMap and LastMap, except using GetCurrMap instead. After the CurrMap and CurrScreen have been written to, I'll make a new check to compare the values of CurrScreen and LastScreen and CurrMap and LastMap. Of course, when I set them to global variables, I'll make sure to check for the Current Map and Screen numbers so everything doesn't get all mixed up. If all 4 are equal to what they're being compared with, everything stays the same. If even ONE is messed up, it'll set SomariaCheck to 0. A few more questions, though:

    1: If I wanted to do an if statement, but check if something is NOT equal to another thing, should I use !== ?
    2: How would you go about setting up the checks I just mentioned? Would you have set to where it'd check for CurrScreen !== LastScreen, and if they don't, check for the Map ones, and if they're not equal, set SomariaCheck to 0, and if they are, do it anyways? Or would you instead check the Screen ones and if not equal, set Check to 0, and if they are, repeat with Map? (Note: This is simply your opinion. I just want to know how other people would do it for efficiency.)
    3: Is there anything else I should do?
    Edit:
    4: Why is it that I can't read from "GetCurScreen()"? It's supposed to only work when you use "game->", right? But everytime I do that, I get a compiler error stating, "Left of the arrow (->). Operator must be a pointer type (ffc, etc.). But Game IS a pointer type! The ZScript FAQ says so!

  6. #16
    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,433
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.08%

    Re: Checking for integers and floats....

    I'll make four new variables, CurrScreen, LastScreen, CurrMap, and LastMap. They'll all be global, of course, or that defeats their purpose.
    Yep. Also, be sure to initialize them to something invalid like -1 to be sure you don't incorrectly get a match on the first use.

    At the start of the script, I'll write the current screen number to CurrScreen using GetCurrScreen. At the end of the script, I'll write to LastScreen by "copying" the value of CurrScreen to it. I'll do the same with CurrMap and LastMap, except using GetCurrMap instead. After the CurrMap and CurrScreen have been written to, I'll make a new check to compare the values of CurrScreen and LastScreen and CurrMap and LastMap.
    You don't need a separate test, actually, just a change to one condition:
    Code:
    if (SomariaCheck == 1 && CurrScreen == LastScreen && CurrMap == LastMap)
    I just realized, though... If you leave the screen and come back, you'll be on the same screen and map, but the block will be gone. This could be a bit tricky, actually...

    1: If I wanted to do an if statement, but check if something is NOT equal to another thing, should I use !== ?
    Almost: it's !=

    2: How would you go about setting up the checks I just mentioned? Would you have set to where it'd check for CurrScreen !== LastScreen, and if they don't, check for the Map ones, and if they're not equal, set SomariaCheck to 0, and if they are, do it anyways? Or would you instead check the Screen ones and if not equal, set Check to 0, and if they are, repeat with Map? (Note: This is simply your opinion. I just want to know how other people would do it for efficiency.)
    For efficiency? Well, you don't really need to set it to 0 at all, since you know you'll just be setting it right back to 1 anyway. I say just check them along with SomariaCheck as above, since they're all part of picking from the same set of actions.
    Efficiency's not a big concern here. Unless you have a ridiculously CPU-intensive way of checking, you won't even notice a difference between two methods.

    3: Is there anything else I should do?
    Hm. Well, again, I'm not entirely certain how you want the script to work. You may want to change the values of the CmbRX variables when the block is placed, but that's only if you want to change it back to what it was before.
    More importantly, there's the question of what to do if the block is pushed. Then you don't know where it is anymore, so you can't replace it. The only solution that springs to mind is to use a unique combo for the created block, so you can scan the whole screen for it and be sure whether you found it or not.
    Then again, I'm not sure what would happen if you used the cane while the block was in mid-push. That might be a serious problem.

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

    Re: Checking for integers and floats....

    Quote Originally Posted by Saffith View Post
    Yep. Also, be sure to initialize them to something invalid like -1 to be sure you don't incorrectly get a match on the first use.

    I'm just setting them both to the Current screen anyways at first. :p

    You don't need a separate test, actually, just a change to one condition:
    Code:
    if (SomariaCheck == 1 && CurrScreen == LastScreen && CurrMap == LastMap)
    I just realized, though... If you leave the screen and come back, you'll be on the same screen and map, but the block will be gone. This could be a bit tricky, actually...

    Actually... That's what it's supposed to do. :p

    Almost: it's !=

    Darn it! XD

    For efficiency? Well, you don't really need to set it to 0 at all, since you know you'll just be setting it right back to 1 anyway. I say just check them along with SomariaCheck as above, since they're all part of picking from the same set of actions.
    Efficiency's not a big concern here. Unless you have a ridiculously CPU-intensive way of checking, you won't even notice a difference between two methods.

    Okay, if you say so!

    Hm. Well, again, I'm not entirely certain how you want the script to work. You may want to change the values of the CmbRX variables when the block is placed, but that's only if you want to change it back to what it was before.
    More importantly, there's the question of what to do if the block is pushed. Then you don't know where it is anymore, so you can't replace it. The only solution that springs to mind is to use a unique combo for the created block, so you can scan the whole screen for it and be sure whether you found it or not.

    Actually, the "CmbRX variables are the reset combos, hence the "R". There's a new and reset variable for each thing I modify on a combo. It's easier to keep track of variable settings that way.

    Then again, I'm not sure what would happen if you used the cane while the block was in mid-push. That might be a serious problem.

    Quite. O_o
    My replies are in bold. :)

    Oh yeah, you missed a question. :p

  8. #18
    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,433
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.08%

    Re: Checking for integers and floats....

    I just realized, though... If you leave the screen and come back, you'll be on the same screen and map, but the block will be gone. This could be a bit tricky, actually...
    Actually... That's what it's supposed to do. :p
    What I mean to say is, if you leave and come back, there won't be a block there, but the script will think there is, so it'll try and replace it. So even tracking the screen and map isn't enough to be certain of whether the block is there...

    Oh yeah, you missed a question. :p
    Yeah, well, . So there.

    4: Why is it that I can't read from "GetCurScreen()"? It's supposed to only work when you use "game->", right? But everytime I do that, I get a compiler error stating, "Left of the arrow (->). Operator must be a pointer type (ffc, etc.). But Game IS a pointer type! The ZScript FAQ says so! :-(
    Are you using "game" or "Game"? It has to be capitalized.
    That's not the error message I would expect in that case, though... Be sure there's not a syntactical error or typo or something just before it.

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

    Re: Checking for integers and floats....

    Quote Originally Posted by Saffith View Post
    What I mean to say is, if you leave and come back, there won't be a block there, but the script will think there is, so it'll try and replace it. So even tracking the screen and map isn't enough to be certain of whether the block is there...

    Yeah, well, . So there.

    Are you using "game" or "Game"? It has to be capitalized.
    That's not the error message I would expect in that case, though... Be sure there's not a syntactical error or typo or something just before it.
    Oh. So... I'll try to figure a workaround to the problem... See, that's why I have the failsafe of "if (Screen->ComboD [SomariaBlockPosition] == 15)"! So, if you're talking about SomariaCheck not getting reset at screen re-entry, then don't worry. :)

    At first, I used "Game". When that didn't work, I put it lowercase. No change. So I just put "GetCurScreen(game)". When Compiling, I got this:

    "Could not match type signature GetCurScreen(WTF)."

    HOW DID GAME TURN OUT TO BE WTF?! I'd report it as a bug, but Ilike silly things like that. It amuses me so much. :)

    I'll try again with Game->. It'd BETTER work this time, or the compiler WILL FEEL MY WRATH. :mad:

    Edit: By the way, I put all that about GetCurScreen in the part where I declare CurScreen as a Global Variable. Perhaps that's the problem?

    Edit2: OH NO! That WAS the problem! That messes up my whole script!

    Edit3: Nevermind. :) But now I have a problem:

    Code:
    // OoA Cane of Somaria- When used, this item will create a block in front of Link if the block in front of him isn't solid. 
    // If the combo is solid, this script does nothing.
    // Variables:
    // Cmb- The combo that the Cane switches a screen's combo to. Simply enter the combo number seen in the combo editor!
    // CmbC- The CSet of the new combo. Only use 0-11 for best results.
    // CmbS- Secret Flag of the new combo.
    // CmbI- Inherent Flag of the new combo.
    // CmbT- Combo type of the new combo.
    // CmbS- Solidity of the new combo. Note: SOLIDITY USES THE BINARY SYSTEM. 1111 is total solidity, which is 15 in decimal.
    // SomariaCheck- A special variable used only for checking if a Somaria Block is already on-screen. Creating a Block
    // sets this Variable to 1. Destroying one sets it to 0. This variable is checked only by one function. DO NOT MESS WITH IT!!!!
    // CmbR- The combo the Block resets to when SomariaCheck is set to 1 when you use this item.
    // CmbRC- CSet the of the reset combo.
    // CmbRT- Cmbo type of the reset combo.
    // CmbRS- Secret Flag of the reset combo.
    // CmbRI- Inherent Flag of the reset combo.
    // CmbRSd- Solidity of the reset combo. Don't mess with this unless you know what you're doing, like with CmbSd.
    
    import "std.zh"
    item script CaneSomaria
    {
    	int SomariaBlockX = 0;
    	int SomariaBlockY = 0;
    	int SomariaCheck = 0;
    	int SomariaBlockPosition = 0;
    	int CurScreen = 0;
    	int LastScreen = 0;
    	int CurMap = 0;
    	int LastMap = 0;
    	int Cmb = 2123;
    	int CmbC = 10;
    	int CmbS = 79;
    	int CmbI = 61;
    	int CmbT = 0;
    	int CmbSd = 15;
    	int CmbR = 0;
    	int CmbRC = 2;
    	int CmbRT = 0;
    	int CmbRS = 0;
    	int CmbRI = 0;
    	int CmbRSd = 0;
    
    	void run()
    	{
    		CurScreen = Game->GetCurScreen();
    		CurMap = Game->GetCurMap();
    		if (CurScreen != LastScreen)
    		{
    			SomariaCheck = 0;
    		}
    		else if (CurMap != LastMap)
    		{
    			SomariaCheck = 0;
    		}
    		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;
    			}
    		}
    		if (Link->Dir == 0)
    		{
    			int BlockCheckY = Link->Y - 32;
    			int BlockCheckX = Link->X;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if (BlockRmndrY <= 8)
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockY = Link->Y - 32;
    				SomariaBlockX = Link->X;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    		}
    		else if (Link->Dir == 1)
    		{
    			int BlockCheckY = Link->Y + 32;
    			int BlockCheckX = Link->X;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if (BlockRmndrY <= 8)
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockY = Link->Y + 32;
    				SomariaBlockX = Link->X;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    
    		}
    		else if (Link->Dir == 2)
    		{
    			int BlockCheckY = Link->Y;
    			int BlockCheckX = Link->X - 32;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if (BlockRmndrY <= 8)
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockX = Link->X - 32;
    				SomariaBlockY = Link->Y;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    		}
    		else if (Link->Dir == 3)
    		{
    			int BlockCheckY = Link->Y;
    			int BlockCheckX = Link->X + 32;
    			float BlockRmndrX = BlockCheckX % 16;
    			if (BlockRmndrX <= 8)
    			{
    				BlockCheckX = BlockCheckX - BlockRmndrX;
    			}
    			else
    			{
    				BlockCheckX = BlockCheckX + 16 - BlockRmndrX;
    			}
    			float BlockRmndrY = BlockCheckY % 16;
    			if ( BlockRmndrY <= 8 )
    			{
    				BlockCheckY = BlockCheckY - BlockRmndrY;
    			}
    			else
    			{ 
    				BlockCheckY = BlockCheckY + 16 - BlockRmndrY;
    			}
    			int BlockPosition = (BlockCheckY & 240)+(BlockCheckX>>4);
    			if (Screen->ComboS [BlockPosition] == 0)
    			{
    				SomariaBlockX = Link->X + 32;
    				SomariaBlockY = Link->Y;
    				float remainder = SomariaBlockX % 16;
    				if (remainder <= 8)
    				{
    					SomariaBlockX = SomariaBlockX - remainder;
    				}
    				else
    				{ 
    					SomariaBlockX = SomariaBlockX + 16 - remainder;
    				}
    				float remainderY = SomariaBlockY % 16;
    				if (remainderY <= 8)
    				{
    					SomariaBlockY = SomariaBlockY - remainderY;
    				}
    				else
    				{
    					SomariaBlockY = SomariaBlockY + 16 - remainderY;
    				}
    				SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    			}
    		}
    		LastScreen = CurScreen;
    		LastMap = CurMap;
    		SomariaCheck = 1;
    	}
    }
    Something's going wrong in the code. Once it hits the point where it uses the CmbRX variables, it spawns the block in the top-left corner, makes the entire screen solid, and prevents any other blocks from appearing. It also won't remove the block that was there before. Somewhere in the script, SomariaBlockPosition is getting reset to 0. Plus, after it puts a block in the top-left corner, it seems to ignore the entire code for making a block appear! What am I doing wrong?

  10. #20
    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,433
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.08%

    Re: Checking for integers and floats....

    Simple problem to fix:
    Code:
    				int SomariaBlockPosition = (SomariaBlockY & 240)+(SomariaBlockX>>4);
    				Screen->ComboD [SomariaBlockPosition] = Cmb;
    				Screen->ComboC [SomariaBlockPosition] = CmbC;
    				Screen->ComboF [SomariaBlockPosition] = CmbS;
    				Screen->ComboI [SomariaBlockPosition] = CmbI;
    				Screen->ComboT [SomariaBlockPosition] = CmbT;
    				Screen->ComboS [SomariaBlockPosition] = CmbSd;
    Take out that "int" before setting SomariaBlockPosition. That's in three different places.

    It's not exactly true that you can't create two variables with the same name. More precisely, you can't create two variables with the same name and scope. If there are two variables with the same name available, the compiler will assume you mean the one with the narrowest scope.
    Code:
    int x = 5; // #1
    {
       int x = 10; // #2
       x = 0; // Modifies #2
    }
    x = 8; // #2 no longer exists; modifies #1
    So what you're doing above is creating a new local variable called SomariaBlockPosition and using that, leaving the global variable untouched.

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