00:00
00:00
Newgrounds Background Image Theme

markololohands just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

I need help with a bug :/

372 Views | 8 Replies
New Topic Respond to this Topic

I need help with a bug :/ 2014-09-16 00:14:27


Here is the link to a game i'm working on:

If you make it to day 20 adventurers come to you, and ask for help funding an adventure. They promise you can keep what they find. to do this, i made a fund variable, and "funds" is increased by 100 every time a button is pressed. after you hit accept, it deducts "funds" from "gold" and sets funds back to 0 so that the next time around it starts over. It works fine the first time through, but i can't seem to get it to work for any time after that. Here is the bit of code for this:

if(aDays == 20)
	{
		trace(funds);
		var AdventureTween:Tween;
		var Adventuer2Tween:Tween;
		AdventureTween = new Tween(AdventureWindow,"x",Strong.easeOut,-296,375,24);
		
				//IF YOU DON'T WANT TO FUND MONEY//
		AdventureWindow.no.addEventListener(MouseEvent.CLICK, noAdven)
		function noAdven(event:MouseEvent)
		{
			AdventureTween = new Tween(AdventureWindow,"x",Strong.easeOut,375,-296,24);
			aDays = aDays - aDays;
		}
				//IF YOU DO WANT TO FUND MONEY//
		AdventureWindow.yes.addEventListener(MouseEvent.CLICK, startAdv)
		function startAdv(event:MouseEvent)
		{
			Adventure2Window.fundText.text = String(funds);
			
			AdventureTween = new Tween(AdventureWindow,"x",Strong.easeOut,375,-296,24);
			Adventuer2Tween = new Tween(Adventure2Window,"x",Strong.easeOut,-296,375,24);
			
			Adventure2Window.upFund.addEventListener(MouseEvent.CLICK, incFund)
			function incFund(event:MouseEvent)
			{
				if(gold >= funds)
				{
					funds = funds + 100;
					trace("funds:",funds);
					Adventure2Window.fundText.text = String(funds);
				}
				if(funds >= gold)
				{
					funds = gold;
					trace("funds:",funds);
					Adventure2Window.fundText.text = String(funds);
				}
			}
			Adventure2Window.downFund.addEventListener(MouseEvent.CLICK, decFund)
			function decFund(event:MouseEvent)
			{
				if(funds <= 100)
				{
					funds = 0;
					trace("funds:",funds);
					Adventure2Window.fundText.text = String(funds);
				}
	
				if(funds > 0)
				{
					trace("funds:",funds);
					funds = funds - 100;
					Adventure2Window.fundText.text = String(funds);
				}
			}
			Adventure2Window.acceptButt.addEventListener(MouseEvent.CLICK, Adventure)
			function Adventure(event:MouseEvent)
			{
						//THIS IS WHERE FUNDS UPDATE IS IN THE ADVENTURE2WINDOW//
						//INCLUDE THE DISCOVERY HERE BASED ON 15% 30% 45%//
				gold = gold - funds;
				adventureOn = true;
				goldText.text = String(gold);
				aDays = aDays - aDays;
				AdventureTween = new Tween(Adventure2Window,"x",Strong.easeOut,375,-296,24);				
			}
		}
	}
		
//WHEN THE ADVENTURES RETURN//
	if(aDays == 10)
	{
		trace(funds);
		trace("Adays = 10")
		if(funds >= 500 && funds <= 10000)//FOR 500 TO 10,000 - 15% CHANCE TO GET//
		{
			funds = funds - funds;
			trace(funds);
			trace(chance);
			AdventureReturn = new Tween(AdventureReturnW,"x",Strong.easeOut,-296,375,24);
			chance = Math.round(Math.random() * 100)
			if(chance >= 0 && chance <= 45)//-----45% CHANCE TO GET THIS ------//
			{
				cloth = cloth + 150;
				itemsMenu.clothAmt.text = String(cloth);
				trace("The adventurer's have retured!")
			}
		}
		if(funds >= 10000 && funds <= 50000)//FOR 500 TO 10,000 - 15% CHANCE TO GET//
		{
			funds = 0;
			trace(chance);
			AdventureReturn = new Tween(AdventureReturnW,"x",Strong.easeOut,-296,375,24);
			chance = Math.round(Math.random() * 100)
			if(chance >= 0 && chance <= 55)//-----55% CHANCE TO GET THIS ------//
			{
				cloth = cloth + 150;
				itemsMenu.clothAmt.text = String(cloth);
				trace("The adventurer's have retured!")
			}
		}
		if(funds >= 50000 && funds <= 100000)//FOR 500 TO 10,000 - 15% CHANCE TO GET//
		{
			funds = 0;
			trace(chance);
			AdventureReturn = new Tween(AdventureReturnW,"x",Strong.easeOut,-296,375,24);
			chance = Math.round(Math.random() * 100)
			if(chance >= 0 && chance <= 75)//-----75% CHANCE TO GET THIS ------//
			{
				cloth = cloth + 150;
				itemsMenu.clothAmt.text = String(cloth);
				trace("The adventurer's have retured!")
			}
		}
		var AdventureReturn:Tween;
		if(adventureOn == true)
		{
			adventureOn = false;
			AdventureReturn = new Tween(AdventureReturnW,"x",Strong.easeOut,-296,375,24);
			funds = funds - funds;
		}
	}
	AdventureReturnW.addEventListener(MouseEvent.CLICK, adventureReturnReturn)
	function adventureReturnReturn(event:MouseEvent)
	{
				AdventureReturn = new Tween(AdventureReturnW,"x",Strong.easeOut,375,-296,24);
	}

it may seem like a lot, but i would really appreciate any help.

Response to I need help with a bug :/ 2014-09-16 00:17:09


Response to I need help with a bug :/ 2014-09-16 13:17:02


Okay so, at this point it increases funds by 300 only if it's the second time funding. I've reread the code hundreds of times and I have no idea why.

Response to I need help with a bug :/ 2014-09-16 16:03:50


At 9/16/14 12:14 AM, CanadaSquare wrote: it may seem like a lot, but i would really appreciate any help.

I didn't find the bug, but a lot potential to clean up&shorten your code, it might be easier finding with shortened code.

At the end you have 3 times the same if where the only difference is 1 number. (the percentage)
Set a variable to the percentage depending on the funds and use it in a single if.
You should also look up how to use 'else if' and 'else' in combination with ifs.
Lines like

aDays = aDays - aDays;

also make little sense, why not just write

aDays = 0;

?

I also recommend to use classes.

It should be relatively easy to track the bug if you put traces in the relevant code which help you identify what exactly is executed. Just check which code is executed how often when the bug happens.

Response to I need help with a bug :/ 2014-09-16 16:17:37


At 9/16/14 01:17 PM, CanadaSquare wrote: I've reread the code hundreds of times and I have no idea why.

Use the debugger and step through your code and understand what's actually going on.
Reading the code again and again to find problems is nonsense.

Response to I need help with a bug :/ 2014-09-16 16:59:05


At 9/16/14 04:17 PM, milchreis wrote:
At 9/16/14 01:17 PM, CanadaSquare wrote: I've reread the code hundreds of times and I have no idea why.
Use the debugger and step through your code and understand what's actually going on.
Reading the code again and again to find problems is nonsense.

for some reason, the debugger tells it has errors wherever I have comments. And that it can't track any because of that.

Response to I need help with a bug :/ 2014-09-16 17:45:22


At 9/16/14 04:59 PM, CanadaSquare wrote: for some reason, the debugger tells it has errors wherever I have comments. And that it can't track any because of that.

What error messages do you get exactly?

Response to I need help with a bug :/ 2014-09-16 18:37:06


The message stopped appearing, I'm sorry. But either way, i'm not sure how to fix this bug..

Response to I need help with a bug :/ 2014-09-16 18:48:30


At 9/16/14 06:37 PM, CanadaSquare wrote: The message stopped appearing, I'm sorry. But either way, i'm not sure how to fix this bug..

Familiarize yourself with the debugger. With it you can look at the variables in your code at runtime, you can also pause at any time and step line-by-line through your code. With that you should be able to figure out this issue pretty easily.


If ya have something to say, PM me. I have a lot of time to spare.

Also never PM egg82.

BBS Signature