Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Variable Help

(96 views • 10 replies)

This topic is 1 page long.

<< < > >>
None

DragonFruit-Rock

Reply To Post Reply & Quote

Posted at: 5/17/08 12:59 PM

DragonFruit-Rock NEUTRAL LEVEL 13

Sign-Up: 12/31/05

Posts: 1,242

NOTE: I WORK IN ACTIONSCRIPT 2, NOT AS3. THANK YOU.

Ok, I really should be able to do this, but whenever I do try, I fail miserably. My problem is combining hittests and variables. Right now I'm just screwing around with a little control design that I started a while back. Here it is so far. See that little 100 in the top left corner? Thats your little squares health. Whenever you hit one of the little black lines, or bullets, I need that number to go down by, lets say 1. I know how to change it and stuff, so it really dosen't matter. Ok, since all the other code is irrelevant il just post the hittest stuff.

onClipEvent (enterFrame) {
if (hitTest(_root.bullet)) {
_root.health-1;
}
}

Honestly I'm a disaster at hittests, but ive tried many tutorials and they dont seem to help, so Im asking you guys. I know this is quite a basic code, but i just cant do hittests. Anyways, ive done everything i know of to make the code work. I've givin the bullets the instance name bullet, ive made the 100 a variable the the place it appears in is a dynamic text box and all that, and you get the idea. Just if you can, please help.

Thanks in advance,
DFR

If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature

None

West-End-Pro

Reply To Post Reply & Quote

Posted at: 5/17/08 01:07 PM

West-End-Pro NEUTRAL LEVEL 23

Sign-Up: 02/15/06

Posts: 2,359

onClipEvent (enterFrame) {
if (this.hitTest(_root.bullet)) {
_root.health -= 1;
// OR _root.health--;
}
}

That should work.


None

hansaW

Reply To Post Reply & Quote

Posted at: 5/17/08 01:09 PM

hansaW FAB LEVEL 09

Sign-Up: 06/12/07

Posts: 35

I am pretty sure that you write -=1 or -- instead of -1 when changing a varable.

Don't forget to put your pants on.


None

DragonFruit-Rock

Reply To Post Reply & Quote

Posted at: 5/17/08 01:15 PM

DragonFruit-Rock NEUTRAL LEVEL 13

Sign-Up: 12/31/05

Posts: 1,242

it didnt. I rechecked all the things like instance names and such, but still nothing.

If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature

Sad

DragonFruit-Rock

Reply To Post Reply & Quote

Posted at: 5/17/08 04:10 PM

DragonFruit-Rock NEUTRAL LEVEL 13

Sign-Up: 12/31/05

Posts: 1,242

Can anybody help please??????

If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature

None

sinz3ro

Reply To Post Reply & Quote

Posted at: 5/18/08 01:13 AM

sinz3ro NEUTRAL LEVEL 07

Sign-Up: 08/02/05

Posts: 598

Are you sure the bullets firing at the box are just called 'bullet' or are they bullet1, bullet2 etc through duplicating or what? Becuase if so you need to chuck a for loop in the hit test code.

// meh

BBS Signature

None

54uR0n

Reply To Post Reply & Quote

Posted at: 5/18/08 03:57 AM

54uR0n NEUTRAL LEVEL 05

Sign-Up: 05/16/08

Posts: 114

At 5/17/08 12:59 PM, DragonFruit-Rock wrote: I've givin the bullets the instance name bullet

Can only one bullet be on the screen at the time? Otherwise, that is going to be problematic.

Like the others suggested using 'var -1' wouldn't change the variable. Use the decrementor operation.

If that doesn't fix it, then put a trace in that condition to see if the hitTest is working, or if it's a problem with the decrement or the variable showing up in the textbox.


None

TrillingBird

Reply To Post Reply & Quote

Posted at: 5/18/08 04:27 AM

TrillingBird LIGHT LEVEL 03

Sign-Up: 04/11/08

Posts: 291

i think u have the hpbar thing wrong i did that in my engine that i just finished lol

if u dont set

_root.health=100

somewhere in your code

and also in the var for the hpbar dynamic text
it wont work


None

UnknownFury

Reply To Post Reply & Quote

Posted at: 5/18/08 04:51 AM

UnknownFury EVIL LEVEL 21

Sign-Up: 08/10/05

Posts: 5,303

Well first of all it should be -= 1 not -1. Secondly, all the bullets cannot be called 'bullet' which is where your problem lies. You are only, presumingly, testing against 1 bullet which has the name bullet and the rest are duplicates with different names. You're going to have to do a for loop, I suppose. However, it may possibly cause lag depending on how big it is.


Questioning

zrb

Reply To Post Reply & Quote

Posted at: 5/18/08 09:38 AM

zrb LIGHT LEVEL 10

Sign-Up: 08/08/06

Posts: 3,851

You're going to have to do a for loop, I suppose.

That might help you. Here's the tutorial for the 'for' loop.

I can speak french :3 || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

None

DragonFruit-Rock

Reply To Post Reply & Quote

Posted at: 5/20/08 01:54 PM

DragonFruit-Rock NEUTRAL LEVEL 13

Sign-Up: 12/31/05

Posts: 1,242

Awesome. Thanks guys, I need to stufy that loop then!

If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature

All times are Eastern Daylight Time (GMT -4) | Current Time: 12:53 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!