Be a Supporter!

Help with bulletholes please!

  • 2,043 Views
  • 60 Replies
New Topic Respond to this Topic
benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Help with bulletholes please! 2009-12-29 05:09:29 Reply

In the game I am making, there is a crosshair movieclip. The crosshair movieclip has a shooting animation and on the 2nd and 3rd frames of this animation there is an invisible square that acts as a bullet scan directly inbetween the crosshairs. Here is the script for the square.

onClipEvent (enterFrame)
{

if (this.hitTest(_root.bgk))
{ _root.attachMovie.this("bulletHole", "<new name>", <depth>, {_x:_root_.xmouse, _y:_root._ymouse});

}// end if
} // end of for

I am trying to make it so, when the rectangle hits the "bgk" movieclip in the main timeline, it creates a bullethole on the exact position of the square.
Here is the error message I keep getting:

Expected a field name after '.' operator.

Thank-you, also... if there is a better code that serves the same purpose, by all means please share it with me!
Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Help with bulletholes please! 2009-12-29 05:20:06 Reply

remove the this. in after attachMovie and actually specify a number in the depth (_root.getNextHighestDepth () would work)


AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
HonterGames
HonterGames
  • Member since: Jun. 18, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Help with bulletholes please! 2009-12-29 05:32:33 Reply

At 12/29/09 05:20 AM, Yambanshee wrote: remove the this. in after attachMovie and actually specify a number in the depth (_root.getNextHighestDepth () would work)

Yeah ^ should work but i think he just used <depth>, etc just as a filler, as an example of wat hed put


BBS Signature
Archawn
Archawn
  • Member since: Sep. 9, 2007
  • Offline.
Forum Stats
Member
Level 27
Game Developer
Response to Help with bulletholes please! 2009-12-29 08:27:25 Reply

Your problem lies in the line:

_root.attachMovie.this("bulletHole", "<new name>", <depth>, {_x:_root._xmouse, _y:_root._ymouse});

If you want to attach the hole to the _root layer, you just need to say:

_root.attachMovie(...);

If you want to attach it inside the crossheir, just say:

this.attachMovie(...);

Also, if you're looking to do either of those things, the _x and _y positions of the hole will be screwed up, due to the current scope you are in. Below, I have code that gets the local position of the invisible square (called "shot"), and transformed it into coordinates on the _root layer.

var numHoles:Number = 0;

onEnterFrame = function(){
	crossheir._x = _xmouse;
	crossheir._y = _ymouse;
}

onMouseDown = function(){
	var hole = _root.attachMovie("hole", "hole"+numHoles, getNextHighestDepth());
	
	var point = new flash.geom.Point(crossheir.shot._x, crossheir.shot._y);
	crossheir.localToGlobal(point);
	
	hole._x = point.x;
	hole._y = point.y;
	
	numHoles++;
}

Finally,

REMEMBER TO NEVER CODE ON MOVIECLIPS.

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-29 17:00:03 Reply

Okay sorry guys, I've decided to use a new code, I am new to this attachmovie stuff and it was getting really confusing for me, here is my new code:

onClipEvent (enterFrame)

{
var i;
if (this.hitTest(_root.bgk))_root.bull.dupl icateMovieClip("bulletNew", i);
if (i == 10) {
i = 0;
}

}

It makes A bullet hole, but that's it, only one bullethole. I want as many as 30 on the screen at the same time. Also, with this code, the bulleholes overlap everything on the main timeline, which is not what I want.

Help please and thank-you!
benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-29 23:03:11 Reply

Boooooooomp

Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Help with bulletholes please! 2009-12-29 23:23:29 Reply

At 12/29/09 05:00 PM, benjadaninja wrote: onClipEvent (enterFrame)

{
var i;
if (this.hitTest(_root.bgk))_root.bull.dupl icateMovieClip("bulletNew", i);
if (i == 10) {
i = 0;
}

}

It makes A bullet hole, but that's it, only one bullethole. I want as many as 30 on the screen at the same time. Also, with this code, the bulleholes overlap everything on the main timeline, which is not what I want.
Help please and thank-you!

-> You never gave the variable i a value.
-> You re declare i every frame.
-> i is never changed.

-> In AS2 clips on the stage in the IDE are exported with negative depths, that you cannot remove with removeMovieClip unless you use the swapDepths() method to change it to a positive index.
-> You say you want 30, yet the if statement restricts it to only 10 (If there was a i++ statement before it)
-> Look up every function/operator I've mentioned here:
swapDepths(), ++, duplicateMovieClip(), removeMovieClip


Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-29 23:31:11 Reply

At 12/29/09 11:23 PM, Montycarlo wrote:
-> In AS2 clips on the stage in the IDE are exported with negative depths, that you cannot remove with removeMovieClip unless you use the swapDepths() method to change it to a positive index.
-> You say you want 30, yet the if statement restricts it to only 10 (If there was a i++ statement before it)
-> Look up every function/operator I've mentioned here:
swapDepths(), ++, duplicateMovieClip(), removeMovieClip

Thanks for the help, but I don't really understand what you are trying to say. I am kind of a noob at AS.

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-30 18:15:29 Reply

Could someone please explain it in greater detail?
Thanks

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Help with bulletholes please! 2009-12-30 18:47:11 Reply

Am I the only one who thought the title was "Help with buttholes please!" for a few seconds?


BBS Signature
benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-30 20:15:05 Reply

Jezus this is hard, can someone please just give me an .fla with working bulletholes?
I know the idea of this is to teach me how to do it by myself, but I don't see that happening.

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-31 00:43:58 Reply

Bump
Sorry, I've tried all these codes and none of them work! Please help!

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Help with bulletholes please! 2009-12-31 01:34:23 Reply

At 12/31/09 12:43 AM, benjadaninja wrote: Bump
Sorry, I've tried all these codes and none of them work! Please help!

You need to understand all these functions you're using. Don't just keep trying random things hoping to get the result you want.

Montycarlo and Archon explained why your code isn't working.

With your last code, the only things you need are, as Montycarlo explained:

-> You never gave the variable i a value.
-> You re declare i every frame.
-> i is never changed.

You declare i ever frame with a null value. (Or is it undefined?) It doesn't have a value, and it will always be like this. Just make i increase in value, and move the declaration of it outside the enterFrame event.

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-31 18:17:57 Reply

k guys I am I doing it right? I tried to specify everything like you guys mentioned to do:

onClipEvent (enterFrame)

{
var bulletHole;
if (this.hitTest(_root.bgk))_root.bulletHol e.duplicateMovieClip(_root.bulletHole1, 30);
_root.bullet._x = this;
_root.bullet._y = this;
if (bulletHole == 30) {
bulletHole = 0;
}

But it still doesn't worrrrrrrkkk :(
benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-31 18:46:47 Reply

I've fucking tried everything, so I am just going to email the .fla to one of you guys is that cool?

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-31 19:41:26 Reply

Here is a link to the file, I hope someone give me a working script out of this, or re-upload it with a working script.
http://www.badongo.com//?page=upload_s_c omplete&s=&msg=Click+here+to+download+yo ur+uploaded+other+file&url=http%3A%2F%2F www.badongo.com%2Ffile%2F19447989&url_ki ll=http%3A%2F%2Fwww.badongo.com%2Fdelete %2Ffile%2Fmz79cyj8%2F19447989&affiliate=
&thumb=0

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2009-12-31 21:42:44 Reply

Also, please refrain from stealing my movieclips...

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Help with bulletholes please! 2010-01-01 04:21:14 Reply

Your code:

onClipEvent (enterFrame)

{
var bulletHole;
if (this.hitTest(_root.bgk))_root.bulletHole.duplicateMovieClip(_root.bulletHole1, 30);
_root.bullet._x = this;
_root.bullet._y = this;
if (bulletHole == 30) {
bulletHole = 0;
}

Is a mess. You did nothing of what was told to you. You just changed the name of a few variables... I haven't even downloaded your fla.

Let's take it step by step shall we?

First line, "var bulletHole;"

You just ignored what everyone said. Why are you declaring this every frame with a null value?? Move it out of the enterFrame event! And y'know, give it a value.

Second, what is this?

_root.bullet._x = this;
_root.bullet._y = this;

"this" equals the name of your movieClip. this._x equals its x value. Same for the way. It won't work the way you have it.

Third:

if (bulletHole == 30) {
bulletHole = 0;
}

Do you honestly expect bulletHole to someday equal 30? You can keep waiting, but it will never equal anything. Do you see anything in your code that makes it equal anything? I don't.

And it doesn't look like you're using this variable anyway...so what's the point?

Don't just keep throwing in stuff to see if it'll work. Please just look up how attachMovie works, and use it.

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Help with bulletholes please! 2010-01-01 04:22:22 Reply

At 1/1/10 04:21 AM, 4urentertainment wrote: "this" equals the name of your movieClip. this._x equals its x value. Same for the way.

Meant: Same for the y value.

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2010-01-01 04:22:24 Reply

Sorry, wrong link. http://spamtheweb.com/ul/upload/010110/8 425_bullehole2.fla

this one's file size is smaller too
flashMan
flashMan
  • Member since: Aug. 24, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Help with bulletholes please! 2010-01-01 11:00:47 Reply

-You need to understand all these functions you're using. Don't just keep trying random things hoping to get the result you want-

To the guy who said this, I do this all the time :P

And it works, so why shouldn't you do this, I don't understand :(

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Help with bulletholes please! 2010-01-01 11:54:15 Reply

At 1/1/10 11:00 AM, cheese123 wrote:
-You need to understand all these functions you're using. Don't just keep trying random things hoping to get the result you want-
To the guy who said this, I do this all the time :P

And it works, so why shouldn't you do this, I don't understand :(

because thats not learning, thats trail and error and grey hair


AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2010-01-04 02:05:49 Reply

last bump yo

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Help with bulletholes please! 2010-01-04 04:05:25 Reply

At 1/4/10 02:05 AM, benjadaninja wrote: last bump yo

Dude, you were given all the answers to your problems. Stop waiting for someone to do all the work for you.

flashMan
flashMan
  • Member since: Aug. 24, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Help with bulletholes please! 2010-01-04 08:33:48 Reply

Just have the bullet hole off the screen, so it can be duplicated

Then do this:

http://lmgtfy.com/?q=Actionscript+Duplic ate+Movie+Clip+

- There problem solved

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2010-01-09 19:58:51 Reply

CS3 version of file:
http://spamtheweb.com/ul/upload/090110/6 4705_bullehole3.fla

Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to Help with bulletholes please! 2010-01-09 20:45:55 Reply

It's obvious you don't know what you're doing. You need to look up all these functions and things and make sure you understand how they work before you try to use them. Leave this for now and practice simpler things until you understand what you're doing.


BBS Signature
benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2010-01-09 23:38:57 Reply

At 1/9/10 08:45 PM, Neo-13 wrote: It's obvious you don't know what you're doing. You need to look up all these functions and things and make sure you understand how they work before you try to use them. Leave this for now and practice simpler things until you understand what you're doing.

I do have some understanding, I can get the holes to duplicate on a mousedown function, but not anyway else... which is what I want.

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2010-01-10 17:22:24 Reply

At 1/9/10 07:58 PM, benjadaninja wrote: CS3 version of file:
http://spamtheweb.com/ul/upload/090110/6 4705_bullehole3.fla

ahem

benjadaninja
benjadaninja
  • Member since: Sep. 16, 2005
  • Offline.
Forum Stats
Member
Level 18
Animator
Response to Help with bulletholes please! 2010-01-19 01:19:55 Reply

Bump for fucksakes, I just want bulletholes in my fucking game, I don't even want to learn anymore. It's been months, I've looked up tutorials, I've tried different codes, I've took baby steps... nothing works. For the love of god can someone please just look at the .fla and recommend a script?