00:00
00:00
Newgrounds Background Image Theme

Altongoodbottle 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!

Constantly fecrease health

641 Views | 13 Replies
New Topic Respond to this Topic

Constantly fecrease health 2012-12-26 15:59:50


Hey I want to constantly decrease health if nothing is done and my frame code is:

if(body._currentframe == "idle"){
		_root.pl-=random(10);
}

So basically the idea is if animation idle for object "body" is played -> decrease health but nothing happens. Why?

Thanks


Please follow my Tumblr?

Response to Constantly fecrease health 2012-12-26 16:26:27


At 12/26/12 03:59 PM, Uniporn wrote: Hey I want to constantly decrease health if nothing is done and my frame code is:

if(body._currentframe == "idle"){
_root.pl-=random(10);
}

So basically the idea is if animation idle for object "body" is played -> decrease health but nothing happens. Why?

Thanks

1) Learn to debug.

Your most powerful debugging tool is the "trace" function.

if(something){
trace("Something is happening!");
}

This would output "Something is happening" when that if statement is working.

You can also output variables.

trace(body._x);

Would output the body's x position.

So in your case, if you added a trace inside the statement, you'd see it doesn't happen. Then you would trace the body._currentFrame, and you'd see that the output is a number, not a string.

MovieClip._currentFrame returns the number of the current frame. I believe there is Movieclip._currentLabel (not sure if that's the exact syntax), but that would be the property that will tell you the frame label.

Hope this helped.

Response to Constantly fecrease health 2012-12-26 16:38:35


Hey thanks!

I changed my code to:

if(body._currentframe == "1"){
	trace("Something is happening!");
		_root.pl-=random(10);
}

You were right! when I replaced the frame label with the frame number I got the output just fine. But only the "Something is happening!" output. "_root.pl-=random(10);" doesn't seem to have any effect on the health, this is weird because I have the following code connected to a button to test health decreasing and it works just fine:

testpl.onRelease=function(pleasure){
	_root.pl-=random(10);

}

Please follow my Tumblr?

Response to Constantly fecrease health 2012-12-26 17:06:26


I get the subtle impression that this is a porn game

at any rate, if you with to continue programming or are planning on building a game out of this (not just buttons or something) then it's very highly recommended that you forget AS2 and learn AS3.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to Constantly fecrease health 2012-12-26 17:13:00


At 12/26/12 05:06 PM, egg82 wrote: I get the subtle impression that this is a porn game

at any rate, if you with to continue programming or are planning on building a game out of this (not just buttons or something) then it's very highly recommended that you forget AS2 and learn AS3.

Is there any reason you are bringing this up?

Hmm I'm using as2 because I didn't rly see why use as3. Is using as2 bad?


Please follow my Tumblr?

Response to Constantly fecrease health 2012-12-26 17:51:52


Yeah, using AS2 is a very very bad practice for someone who wants to be a good programmer at some point, if you're more of an artist and I don't really care how good your coding abilities are then AS2 is for you, that's what it was designed for. If you actually want to program larger games in the future then you'll want to be using AS3.


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

Also never PM egg82.

BBS Signature

Response to Constantly fecrease health 2012-12-26 18:03:34


At 12/26/12 05:51 PM, MintPaw wrote: Yeah, using AS2 is a very very bad practice for someone who wants to be a good programmer at some point, if you're more of an artist and I don't really care how good your coding abilities are then AS2 is for you, that's what it was designed for. If you actually want to program larger games in the future then you'll want to be using AS3.

Oh no, I'm an animation :) and am just doing this for fun. Thanks for the input tho. Btw can you help me with my problem? the second one, that I mentioned in my first reply.


Please follow my Tumblr?

Response to Constantly fecrease health 2012-12-26 18:59:55


Ok I played a bit with the code and this is what I have

do{

_root.pl+=random(10);

}
while(_root.pl<=100)

so the point is add health while health is lower than 100. But it freezes. Does anyone know why?


Please follow my Tumblr?

Response to Constantly fecrease health 2012-12-26 19:18:45


At 12/26/12 06:59 PM, Uniporn wrote: so the point is add health while health is lower than 100. But it freezes. Does anyone know why?

be careful with while and do loops, because if you don't have a guaranteed way to break out of it it'll crash.

problem is, any number of things could be affecting the outcome of the health bar (could even be something not remotely tied to it) - and we can't know for sure what's going on. Welcome to AS2.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to Constantly fecrease health 2012-12-27 05:42:31


At 12/26/12 05:51 PM, MintPaw wrote: Yeah, using AS2 is a very very bad practice for someone who wants to be a good programmer at some point, if you're more of an artist and I don't really care how good your coding abilities are then AS2 is for you, that's what it was designed for. If you actually want to program larger games in the future then you'll want to be using AS3.

MintPaw, I think it's possible to use AS2 and still be a good programmer. I admit it, AS2 did introduce me to bad habits like absolute addressing, onClipEvent, etc., at first, but I've seen kicked those. Now I always use relative addressing, listeners, declare a variable's type before using it, and so on.

Response to Constantly fecrease health 2012-12-27 10:51:47


At 12/27/12 05:42 AM, FlyingColours wrote: I admit it, AS2 did introduce me to bad habits like absolute addressing, onClipEvent, etc.

That's not AS2, it is AS1. AS3 syntax still the same as AS2 and the introduction to object oriented programming was already possible in the previous language, of course nothing compared to AS3.

Response to Constantly fecrease health 2012-12-29 00:40:54


The problem is that you have

Math.random(10);

when you're supposed to have

Math.random()*10;
unless I'm wrong

You can't know what you don't know if you can only use yourself as a reference point.

Response to Constantly fecrease health 2012-12-29 01:15:13


At 12/27/12 05:42 AM, FlyingColours wrote: MintPaw, I think it's possible to use AS2 and still be a good programmer. I admit it, AS2 did introduce me to bad habits like absolute addressing, onClipEvent, etc., at first, but I've seen kicked those. Now I always use relative addressing, listeners, declare a variable's type before using it, and so on.

Actually that's AS1, in AS2 classes were introduced and it all looks very similar to AS3, but it allowed for AS1 function to still run such as the onClipEvent() function of Flash 5 back in about 1999. Here in lies the problem, it is very possible to use AS2 well, but learning from online tuts will make you suck pretty bad AS1.5 as I'd like to call it.

At 12/29/12 12:40 AM, Rational-Delirium wrote: The problem is that you have
Math.random(10);

Actually Math.random() is not the same as random(), random(10) will actually generate a number between 0-10. It's an old AS1 function, I do suggest Math.random().

What you want to probably want to do is this:

onEnterFrame = function()
{
	if(body._currentframe == "idle")
	{
		pl-=random(10);
	}
}

By wrapping it in an onEnterFrame event the code runs every frame rather that just once.


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

Also never PM egg82.

BBS Signature

Response to Constantly fecrease health 2012-12-29 02:27:41


I see. I confess that these habits I acquired from a Flash 8 book that still used AS1 for some reason, but I've read another book that teaches you OOP with AS2 and it still uses onClipEvent and other AS1 elements. It appears that even experienced AS2 programmers can fall into this trap.

At 12/29/12 01:15 AM, MintPaw wrote:
At 12/27/12 05:42 AM, FlyingColours wrote: MintPaw, I think it's possible to use AS2 and still be a good programmer. I admit it, AS2 did introduce me to bad habits like absolute addressing, onClipEvent, etc., at first, but I've seen kicked those. Now I always use relative addressing, listeners, declare a variable's type before using it, and so on.
Actually that's AS1, in AS2 classes were introduced and it all looks very similar to AS3, but it allowed for AS1 function to still run such as the onClipEvent() function of Flash 5 back in about 1999. Here in lies the problem, it is very possible to use AS2 well, but learning from online tuts will make you suck pretty bad AS1.5 as I'd like to call it.

At 12/29/12 12:40 AM, Rational-Delirium wrote: The problem is that you have
Math.random(10);
Actually Math.random() is not the same as random(), random(10) will actually generate a number between 0-10. It's an old AS1 function, I do suggest Math.random().

What you want to probably want to do is this:

onEnterFrame = function()
{
if(body._currentframe == "idle")
{
pl-=random(10);
}
}

By wrapping it in an onEnterFrame event the code runs every frame rather that just once.