User Tag List

Results 1 to 10 of 35

Thread: Checking for integers and floats....

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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,436
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.58%

    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.

  2. #2
    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,279
    Level
    24
    vBActivity - Bars
    Lv. Percent
    44.44%

    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

  3. #3
    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,436
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.58%

    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.

  4. #4
    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,279
    Level
    24
    vBActivity - Bars
    Lv. Percent
    44.44%

    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?

  5. #5
    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,436
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.58%

    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.

  6. #6
    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,279
    Level
    24
    vBActivity - Bars
    Lv. Percent
    44.44%

    Re: Checking for integers and floats....

    Too late, Saffith- I finished the script. I defeated many bugs, and it's now perfected and in Script Showcase. Go check it out. This thread (and all the other ones with the questions I asked) can be closed now. :)

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