User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: A Super-annoying, Rand()-related problem

  1. #1
    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.92%

    A Super-annoying, Rand()-related problem

    I don't know the rules about double-posting here, so I'm just making a new thread. Sorry.

    I'm having a problem with Rand() in this script:
    Code:
    // Shovel- Well, what do you THINK it does? :P It digs up the ground directly in front of you,
    // provided it's not solid or a certain combo. The combos it can't dig up are yours to decide!
    // However, I give you three solid combos it CAN dig up, so use them wisely.
    // Variables:
    // ComboDug- Combo that appears when you dig in a diggable spot.
    // Combo1- First Combo you can't dig in.
    // Combo2- 2nd Combo you can't dig in.
    // Combo3- 3rd No-Dig Combo.
    // Combo4- 4th No-Dig Combo.
    // Combo5- 5th No-Dig Combo.
    // ComboS1- First Solid Combo you can dig in.
    // ComboS2- 2nd Solid Dig Combo.
    // ComboS3- 3rd Solid Dig Combo.
    // Random/Random2/Random3- Don't mess with these.
    // BuriedItem- What Special Item you get from certain combos.
    // ComboX & ComboY- Leave this alone.
    // SpclItmCmb1-Cmb4- These 4 combos are the combos that give you special items when dug up! :D
    // ModItem- Leave this alone.
    // NewItem- Leave this alone.
    // ModNPC- See Above.
    // NewNPC- See above, also.
    // Note: Wow! So many variables! Ummm... Nothing I can do about it. =/
    
    import "std.zh"
    item script Shovel
    {
    	int ComboDug = 55;
    	int Combo1 = 47;
    	int Combo2 = 0;
    	int Combo3 = 0;
    	int Combo4 = 0;
    	int Combo5 = 0;
    	int ComboS1 = 322;
    	int ComboS2 = 0;
    	int ComboS3 = 0;
    	int ComboX = 0;
    	int ComboY = 0;
    	int ComboSDug = 1;
    	int Random = 0;
    	int Random2 = 0;
    	int Random3 = 0;
    	int BuriedItem = 0;
    	int SpclItmCmb1 = 0;
    	int SpclItmCmb2 = 0;
    	int SpclItmCmb3 = 0;
    	int SpclItmCmb4 = 0;
    	int ModItem = 0;
    	int NewItem = 0;
    	int ModNPC = 0;
    	int NewNPC = 0;
    
    	void run()
    	{
    		if (Link->Dir == 0)
    		{
    			int BlockCheckY = Link->Y - 16;
    			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->ComboD [BlockPosition] == Combo1 || Screen->ComboD [BlockPosition] == Combo2 || Screen->ComboD [BlockPosition] == Combo3 || Screen->ComboD [BlockPosition] == Combo4 || Screen->ComboD [BlockPosition] == Combo5 || Screen->ComboD [BlockPosition] ==ComboDug) || (Screen->ComboS [BlockPosition] == 15 && (Screen->ComboD [BlockPosition] != ComboS1 && Screen->ComboD [BlockPosition] != ComboS2 && Screen->ComboD [BlockPosition] != ComboS3)) )
    			{
    				Game->PlaySound(6);
    				Quit();
    			}
    				ComboY = Link->Y - 16;
    				ComboX = Link->X;
    				float remainder = ComboX % 16;
    				if (remainder <= 8)
    				{
    					ComboX = ComboX - remainder;
    				}
    				else
    				{ 
    					ComboX = ComboX + 16 - remainder;
    				}
    				float remainderY = ComboY % 16;
    				if (remainderY <= 8)
    				{
    				ComboY = ComboY - remainderY;
    				}
    				else
    				{
    					ComboY = ComboY + 16 - remainderY;
    				}
    				int ComboPosition = (ComboY & 240)+(ComboX>>4);
    			if (Screen->ComboD [BlockPosition] == ComboS1 || Screen->ComboD [BlockPosition] == ComboS2 || Screen->ComboD [BlockPosition] == ComboS3)
    			{
    				Screen->ComboD [ComboPosition] = ComboSDug;
    			}
    			else
    			{
    				Screen->ComboD [ComboPosition] = ComboDug;
    			}
    		}
    		else if (Link->Dir == 1)
    		{
    			int BlockCheckY = Link->Y + 16;
    			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->ComboD [BlockPosition] == Combo1 || Screen->ComboD [BlockPosition] == Combo2 || Screen->ComboD [BlockPosition] == Combo3 || Screen->ComboD [BlockPosition] == Combo4 || Screen->ComboD [BlockPosition] == Combo5 || Screen->ComboD [BlockPosition] == ComboDug) || (Screen->ComboS [BlockPosition] == 15 && (Screen->ComboD [BlockPosition] != ComboS1 && Screen->ComboD [BlockPosition] != ComboS2 && Screen->ComboD [BlockPosition] != ComboS3)) )
    			{
    				Game->PlaySound(6);
    				Quit();
    			}
    				ComboY = Link->Y + 16;
    				ComboX = Link->X;
    				float remainder = ComboX % 16;
    				if (remainder <= 8)
    				{
    					ComboX = ComboX - remainder;
    				}
    				else
    				{ 
    					ComboX = ComboX + 16 - remainder;
    				}
    				float remainderY = ComboY % 16;
    				if (remainderY <= 8)
    				{
    				ComboY = ComboY - remainderY;
    				}
    				else
    				{
    					ComboY = ComboY + 16 - remainderY;
    				}
    				int ComboPosition = (ComboY & 240)+(ComboX>>4);
    			if (Screen->ComboD [BlockPosition] == ComboS1 || Screen->ComboD [BlockPosition] == ComboS2 || Screen->ComboD [BlockPosition] == ComboS3)
    			{
    				Screen->ComboD [ComboPosition] = ComboSDug;
    			}
    			else
    			{
    				Screen->ComboD [ComboPosition] = ComboDug;
    			}
    		}
    		else if (Link->Dir == 2)
    		{
    			int BlockCheckY = Link->Y;
    			int BlockCheckX = Link->X - 16;
    			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->ComboD [BlockPosition] == Combo1 || Screen->ComboD [BlockPosition] == Combo2 || Screen->ComboD [BlockPosition] == Combo3 || Screen->ComboD [BlockPosition] == Combo4 || Screen->ComboD [BlockPosition] == Combo5 || Screen->ComboD [BlockPosition] == ComboDug) || (Screen->ComboS [BlockPosition] == 15 && (Screen->ComboD [BlockPosition] != ComboS1 && Screen->ComboD [BlockPosition] != ComboS2 && Screen->ComboD [BlockPosition] != ComboS3)) )
    			{
    				Game->PlaySound(6);
    				Quit();
    			}
    				ComboY = Link->Y;
    				ComboX = Link->X - 16;
    				float remainder = ComboX % 16;
    				if (remainder <= 8)
    				{
    					ComboX = ComboX - remainder;
    				}
    				else
    				{ 
    					ComboX = ComboX + 16 - remainder;
    				}
    				float remainderY = ComboY % 16;
    				if (remainderY <= 8)
    				{
    				ComboY = ComboY - remainderY;
    				}
    				else
    				{
    					ComboY = ComboY + 16 - remainderY;
    				}
    				int ComboPosition = (ComboY & 240)+(ComboX>>4);
    			if (Screen->ComboD [BlockPosition] == ComboS1 || Screen->ComboD [BlockPosition] == ComboS2 || Screen->ComboD [BlockPosition] == ComboS3)
    			{
    				Screen->ComboD [ComboPosition] = ComboSDug;
    			}
    			else
    			{
    				Screen->ComboD [ComboPosition] = ComboDug;
    			}	
    		}
    		else if (Link->Dir == 3)
    		{
    			int BlockCheckY = Link->Y;
    			int BlockCheckX = Link->X + 16;
    			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->ComboD [BlockPosition] == Combo1 || Screen->ComboD [BlockPosition] == Combo2 || Screen->ComboD [BlockPosition] == Combo3 || Screen->ComboD [BlockPosition] == Combo4 || Screen->ComboD [BlockPosition] == Combo5 || Screen->ComboD [BlockPosition] == ComboDug) || (Screen->ComboS [BlockPosition] == 15 && (Screen->ComboD [BlockPosition] != ComboS1 && Screen->ComboD [BlockPosition] != ComboS2 && Screen->ComboD [BlockPosition] != ComboS3)) )
    			{
    				Game->PlaySound(6);
    				Quit();
    			}
    				ComboY = Link->Y;
    				ComboX = Link->X + 16;
    				float remainder = ComboX % 16;
    				if (remainder <= 8)
    				{
    					ComboX = ComboX - remainder;
    				}
    				else
    				{ 
    					ComboX = ComboX + 16 - remainder;
    				}
    				float remainderY = ComboY % 16;
    				if (remainderY <= 8)
    				{
    				ComboY = ComboY - remainderY;
    				}
    				else
    				{
    					ComboY = ComboY + 16 - remainderY;
    				}
    				int ComboPosition = (ComboY & 240)+(ComboX>>4);
    			if (Screen->ComboD [BlockPosition] == ComboS1 || Screen->ComboD [BlockPosition] == ComboS2 || Screen->ComboD [BlockPosition] == ComboS3)
    			{
    				Screen->ComboD [ComboPosition] = ComboSDug;
    			}
    			else
    			{
    				Screen->ComboD [ComboPosition] = ComboDug;
    			}
    		}
    		Game->PlaySound(61);
    		Random = Floor(Random);
    		Random = Rand(19);
    		Random2 = Floor(Random2);
    		Random2 = Rand (4);
    		int ComboPosition = (ComboY & 240)+(ComboX>>4);
    		if (Screen->ComboD [ComboPosition] != SpclItmCmb1 && Screen->ComboD [ComboPosition] != SpclItmCmb2 && Screen->ComboD [ComboPosition] != SpclItmCmb3 && Screen->ComboD [ComboPosition] != SpclItmCmb4 && Screen->ComboD [ComboPosition] != ComboS1 && Screen->ComboD [ComboPosition] != ComboS2 && Screen->ComboD [ComboPosition] != ComboS3)
    		{
    		if (Random == 0 || Random == 1 || Random == 2 || Random == 3 || Random == 4 || Random == 11)
    		{
    			Quit();
    		}
    		else if (Random == 5 || Random == 6 || Random == 7 || Random == 8 || Random == 16 || Random == 17)
    		{
    			if (Random2 == 0 || Random2 == 1 || Random2 == 2)
    			{
    				Screen->CreateItem(0);
    				NewItem = Screen->NumItems();
    				item ModItem = Screen->LoadItem(NewItem);
    				ModItem->X = ComboX;
    				ModItem->Y = ComboY;
    			}
    			else if (Random2 == 3)
    			{
    				Screen->CreateItem(2);
    				NewItem = Screen->NumItems();
    				item ModItem = Screen->LoadItem(NewItem);
    				ModItem->X = ComboX;
    				ModItem->Y = ComboY;
    			}
    		}
    		else if (Random == 9 || Random == 10)
    		{
    			Screen->CreateItem(5);
    			ModItem = Screen->NumItems();
    			item NewItem = Screen->LoadItem(ModItem);
    			NewItem->X = ComboX;
    			NewItem->Y = ComboY;
    		}
    		else if (Random == 12 || Random == 13)
    		{
    			Screen->CreateNPC(44);
    			ModNPC = Screen->NumNPCs();
    			npc NewNPC = Screen->LoadNPC(ModNPC);
    			NewNPC->X = ComboX;
    			NewNPC->Y = ComboY;
    		}
    		else if (Random == 14)
    		{
    			Screen->CreateItem(40);
    			NewItem = Screen->NumItems();
    			item ModItem = Screen->LoadItem(NewItem);
    			ModItem->X = ComboX;
    			ModItem->Y = ComboY;
    		}
    		else if (Random == 15)
    		{
    			Screen->CreateNPC(80);
    			ModNPC = Screen->NumNPCs();
    			npc NewNPC = Screen->LoadNPC(ModNPC);
    			NewNPC->X = ComboX;
    			NewNPC->Y = ComboY;
    		}
    		}
    		else if (Screen->ComboD [ComboPosition] == ComboS1 || Screen->ComboD [ComboPosition] != ComboS2 || Screen->ComboD [ComboPosition] != ComboS3)
    		{
    			Random3 = Floor(Random3);
    			Random3 = Rand(13);
    			if (Random3 == 0 || Random3 == 1 || Random3 == 2 || Random3 == 3 || Random3 == 4 || Random3 == 5 || Random3 == 6)
    			{
    				Quit();
    			}
    			else if (Random3 == 7 || Random3 == 8 || Random3 == 9 || Random3 == 10 || Random3 == 11 || Random3 == 12)
    			{
    				if (Random2 == 0 || Random2 == 1 || Random2 == 2)
    				{
    					Screen->CreateItem(0);
    					NewItem = Screen->NumItems();
    					item ModItem = Screen->LoadItem(NewItem);
    					ModItem->X = ComboX;
    					ModItem->Y = ComboY;
    				}
    				else if (Random2 == 3)
    				{
    					Screen->CreateItem(2);
    					NewItem = Screen->NumItems();
    					item ModItem = Screen->LoadItem(NewItem);
    					ModItem->X = ComboX;
    					ModItem->Y = ComboY;
    				}
    			}
    		}
    	}
    }
    I asked Koopa for help earlier, and he told me to use "Random=Floor(Random)" to turn the Random variables back into ints, but.... It's not working. The last bit of code that begins all the randomizing and stuff is supposed to randomly create certain things when you use it on a diggable combo. Problem is, NOTHING HAPPENS. Koopa says that Rand() keeps turning out 0, but.... I can't fix it, and Koopa left me NO instructions on how to use it. (He also said he fixed the code and got it to work, but never sent it to me. ) So, I'm at a loss. Yes, this is my Shovel script, but it'll never be complete until it can produce items. Does anyone know what I'm doing wrong?

  2. #2
    Octorok
    Join Date
    Oct 2006
    Age
    47
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    969
    Level
    10
    vBActivity - Bars
    Lv. Percent
    78.83%

    Re: A Super-annoying, Rand()-related problem

    Why are you doing this?
    Code:
    Random = Floor(Random);
    Random = Rand(19);
    Random2 = Floor(Random2);
    Random2 = Rand (4);
    What you are doing is taking the floor of the contents of Random, then setting it to a new random number right afterward. I'm guessing you meant to do this:

    Code:
    Random = Rand(19);
    Random = Floor( Random );
    Random2 = Rand(4);
    Random2 = Floor( Random2 );
    This set Random to a random number and then take the floor of it. You could even shorten it to:

    Code:
    Random = Floor( Rand(19) );
    Random2 = Floor( Rand(4) );
    You have other places in the code that do this too, this was just an example.

  3. #3
    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.92%

    Re: A Super-annoying, Rand()-related problem

    Quote Originally Posted by blue_knight View Post
    Why are you doing this?
    Code:
    Random = Floor(Random);
    Random = Rand(19);
    Random2 = Floor(Random2);
    Random2 = Rand (4);
    What you are doing is taking the floor of the contents of Random, then setting it to a new random number right afterward. I'm guessing you meant to do this:

    Code:
    Random = Rand(19);
    Random = Floor( Random );
    Random2 = Rand(4);
    Random2 = Floor( Random2 );
    This set Random to a random number and then take the floor of it. You could even shorten it to:

    Code:
    Random = Floor( Rand(19) );
    Random2 = Floor( Rand(4) );
    You have other places in the code that do this too, this was just an example.
    I did that originally, and THAT didn't work! And I have no clue why! ;_;

    Edit: Oh crud! It's doing it AGAIN for another script! This time, I'm trying to randomize the position of something on the screen. Problem is, even with everything right, NOTHING HAPPENS. I even used "Floor" for the Rand()s. It's not working. And no, I will NOT post the script, for I intend for this script to remain secret until I release it. :)

  4. #4
    Octorok
    Join Date
    Oct 2006
    Age
    47
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    969
    Level
    10
    vBActivity - Bars
    Lv. Percent
    78.83%

    Re: A Super-annoying, Rand()-related problem

    Ok you need to see what kind of numbers Rand() is returning. Use the Trace function to output the results to the "allegro.log". Try doing this:

    Trace( Rand(19) );

    or whatever number you want. Then test your script in the viewer, after that look in the "allegro.log" file and let me know what values are in there. We'll figure out what's going on :)

  5. #5
    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.92%

    Re: A Super-annoying, Rand()-related problem

    And then I'm back to square one. Koopa did that, and told me it was going from an int to a float, and told me to use Floor to turn it back into an int. So what good is it going to do to retrace his steps ALL OVER AGAIN?

    Edit: I tried Trace, but.... Problem is, I can never make heads or tails of the ZASM output. What exactly am I looking for? Do I have to USE the script, and not just compile it?

  6. #6
    Keese
    Join Date
    Aug 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    831
    Level
    10
    vBActivity - Bars
    Lv. Percent
    8.52%

    Re: A Super-annoying, Rand()-related problem

    Disregard this post.

  7. #7
    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.92%

    Re: A Super-annoying, Rand()-related problem

    Uhhh.... I didn't even SEE the original post. O.o

  8. #8
    Keese
    Join Date
    Aug 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    831
    Level
    10
    vBActivity - Bars
    Lv. Percent
    8.52%

    Re: A Super-annoying, Rand()-related problem

    I wish we could delete posts here. It was just an unessary question.

  9. #9
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.51%

    Re: A Super-annoying, Rand()-related problem

    Has this been sorted out, or are there still questions/bugs?
    For the record Rand(), for positive arguments, should ALWAYS return an integer.

  10. #10
    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.92%

    Re: A Super-annoying, Rand()-related problem

    Quote Originally Posted by DarkDragon View Post
    Has this been sorted out, or are there still questions/bugs?
    For the record Rand(), for positive arguments, should ALWAYS return an integer.
    Bugs. This is 2.11 b16c, though. Even FLOORING Rand() won't make it work. I haven't tested it out yet, but on my surprise special script (which I really don't want to reveal, for some reason), I have a variable that accesses a Randomized variable in a scope INSIDE the scope the Rand. variable is in. Problem being? Both variables are global, so it shouldn't matter, right? I'm going to try moving things around a bit, though, just in case them being global has no bearing on the matter.... =/ I'll get back to you soon.

    Edit: O_o Nope. Moving it didn't work. I have NO clue what is wrong here....

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