Be a Supporter!
Response to: Array/For Loop Problem Posted April 8th, 2010 in Game Development

At 4/8/10 07:28 AM, LeechmasterB wrote: Your idea about using a couple of arrays is way overcomplicated. Have a look at classes and as files. All you need is a class for enemy (which could extend from the same baseclass as player). With a little bit of OOP practice your loop will only have to run about 1 line of code, namely the update function of your enemies/player.

Yeah, I started looking at OOP a while after posting this, and I probably will change it soon, once I fully understand it. It would still be helpful to know what's causing this, though.

At 4/7/10 09:40 PM, FatalFuryX wrote: Change the fps to 1 and put a trace function in the enemy loop to see where they are on screen

328.95
328.95
328.95
328.95
-107374182.4
-107374182.4
-107374182.4
-107374182.4

328.95 was their starting position, and then it suddenly jumps to . . . negative one million . . .
It doesn't change after that, at all.

Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

Yep, just tried it in, good idea, no cigar though.
Damn, lol.
Probably fixed a bunch of other stuff in it, but the main problem is still there.

Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

OH.
*slaps self*
Thanks dude, I did not think of that at all.

Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

Bump for slow forum day?

About 12 hours and counting so far
Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

At 4/7/10 04:25 PM, tomdeaap wrote: .... I see no code that instantiates ( or howerver the .. you write that ) the enemies. It might be me looking over it, or didn't you made those variables?

What do you mean? I've actually drawn the enemies, and e1-e4 are their instance names.

And to stop you saying something along the lines of "You need to draw/declare them within the code", I have a slightly older version of this, with a simplified loop/array thing, and only one enemy in the
array, and it works perfectly. It's something about having the two other arrays or something else that's
messing it up.

Response to: Usher is cool again Posted April 7th, 2010 in General

Nope.

Response to: The School Pictures Database Posted April 7th, 2010 in General

A ha ha ha, nice one.

Response to: bad translator fun! Posted April 7th, 2010 in General

3 good ones: (All 54 translations later)
cum to Human Resources
penis to Upload
vagina to Full

Response to: ActionScript Problem Posted April 7th, 2010 in Game Development

AS3 Main
Flashkit
Adobe.com
Lots more, use google, there's also books.

Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

Changed the fps again to try and see what's going on. In stead of what i said before, anything in hitArray does not appear at all when I run the code.

I seriously have no idea what's going on here.

Response to: Really weird bumper problem! Posted April 7th, 2010 in Game Development

Try putting all your code into something like this:

if(currentFrame == "Level 1 or w/e"){
//All your code
}

That way, your code will only run for that frame.

Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

At 4/7/10 12:02 PM, Johnny wrote: 2) I didn't go through your code too detailed, but I see that you're multiplying moveArray elements (which equal 0) by another number. Unless you're adding a number to moveArray somewhere, the final product will always be zero (since 0 times anything is 0)
4) It will continue to add that number. You'll want a cap for it somewhere or the number will get obscene. if(finalMovementAmount > 10){finalMovementAmount = 10;}

Yeah this is what my problem is, but it is being added somewhere. The multiplying is for deceleration when the player isn't throwing them around.
When I commented various parts out, I saw that even when I didn't have anything adding any value to moveArray, they still moved. Fast.
The same for gravity, except that's meant to happen. The trouble is, they don't stop at the ground.
I've also tried capping off both at 10, doesn't have any effect at all.

Won't really need too, since those will just be variables now, instead of elements in an array.

Eh, I didn't explain part of that well enough. There does need to be arrays since the way the rest of my code works, each enemy needs its own gravity variable, otherwise I would've made it just one.

3) If you put it at 1fps and it kind of works... why not keep it at your original fps and make the variable lower? Instead of gravity = 10, make it gravity = 2, or gravity = .1;

Also, it didn't work at 1fps, but It let me see what was going on, as at 30 it happened nearly instantly.

Since I'm not sure that you understand what's going on in my end:
Frame 1: Everything is floating in the air, where I left it on the stage.
Frame 2: Player starts to drift down normally. One enemy (e2) has completely vanished.
Frame 3: Only the player remains on screen.

=S

Response to: AS 2.0 more help Posted April 7th, 2010 in Game Development

Are you trying to make it so when "player" hits a cookie, the counter goes up? If that's the case, instead of

_root.cookieCounter.gotoAndPlay(2)

just make a variable called cookiecount, make a dynamic textbox and give it cookiecount as a var, then put

cookiecount++;

instead of the code above.

Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

Anyone?

Response to: Array/For Loop Problem Posted April 7th, 2010 in Game Development

Since no one is posting, il give you the full code which when I run it, shit hits the fan.

//Movement vars
var up:Boolean = false;
var right:Boolean = false;
var down:Boolean = false;
var left:Boolean = false;
var xspeed:Number = 0;
var xAcl:Number = 0.5;
var xLimit:Number = 6;
var xDecay:Number = 0.8;
var exspeed:Number = 0;
var eDecay:Number = 0.8;

//Attacking vars
var upAtk:Boolean = false;
var rightAtk:Boolean = false;
var downAtk:Boolean = false;
var leftAtk:Boolean = false;
var atkPower:Number = 0.6;
var multi:Number = 6;
var xRange:Boolean;
var yRange:Boolean;
var rightSide:Boolean;
var leftSide:Boolean;
var pRange:Number = 30;

//Gravity vars
var gravity:Number = 10;
var gravity2:Number = 10;
var gravAcl:Number = 0.5;
var gravMax:Number = 12;
var groundHit:Boolean = false;

//Others
var halfP:Number = player.width/2;
var halfE:Number = e1.width/2;
var hitArray:Array = new Array();
var moveArray:Array = new Array("0","0","0","0");
var gravArray:Array = new Array("10","10","10","10");
var i:Number;

function keyDowns(event:KeyboardEvent) {
	if (event.keyCode == 87) {
		up = true;
	}
	if (event.keyCode == 68) {
		right = true;
	}
	if (event.keyCode == 83) {
		down = true;
	}
	if (event.keyCode == 65) {
		left = true;
	}
	if (event.keyCode == 38) {
		upAtk = true;
	}
	if (event.keyCode == 39) {
		rightAtk = true;
	}
	if (event.keyCode == 40) {
		downAtk = true;
	}
	if (event.keyCode == 37) {
		leftAtk = true;
	}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDowns);
function keyUps(event:KeyboardEvent) {
	if (event.keyCode == 87) {
		event.keyCode = 0;
		up = false;
	}
	if (event.keyCode == 65) {
		event.keyCode = 0;
		left = false;
	}
	if (event.keyCode == 68) {
		event.keyCode = 0;
		right = false;
	}
	if (event.keyCode == 83) {
		event.keyCode = 0;
		down = false;
	}
	if (event.keyCode == 37) {
		event.keyCode = 0;
		leftAtk = false;
	}
	if (event.keyCode == 38) {
		event.keyCode = 0;
		upAtk = false;
	}
	if (event.keyCode == 39) {
		event.keyCode = 0;
		rightAtk = false;
	}
	if (event.keyCode == 40) {
		event.keyCode = 0;
		downAtk = false;
	}
}
stage.addEventListener(KeyboardEvent.KEY_UP, keyUps);

function stuff(e:Event) {
	//PLAYER MOVEMENT/COLLISIONS/GRAVITY
	//Movement
	if (right == true && xspeed < 0) {
		xspeed += (xAcl * 1.5);
	} else if (right == true && xspeed >= 0) {
		xspeed += xAcl;
	} else if (left == true && xspeed > 0) {
		xspeed -= (xAcl * 1.5);
	} else if (left == true && xspeed <= 0) {
		xspeed -= xAcl;
	} else if (left == false && right == false) {
		xspeed *= xDecay;
	}
	if (xspeed <= -xLimit) {
		xspeed = -xLimit;
	} else if (xspeed >= xLimit) {
		xspeed = xLimit;
	}
	player.x += xspeed;
	//Gravity
	if (gravity <= gravMax - 0.1) {
		up = false;
	}
	if (up == true && groundHit == true) {
		gravity *= -1;
	} else if (up == false) {
		gravity = gravity;
	}
	gravity += gravAcl;
	player.y += gravity;
	//Ground
	groundHit = false;
	if (player.y > ground.y && player.x <= ground.x + (ground.width/2) + halfP && player.x >= ground.x - (ground.width/2) - halfP) {
		player.y = ground.y;
		gravity = gravMax;
		groundHit = true;
	}
	//ENEMY LOOPS
	hitArray.push(e1);
	hitArray.push(e2);
	hitArray.push(e3);
	hitArray.push(e4);
	for (i = 0; i < hitArray.length; i++) {
		hitArray[i].y += gravArray[i];
		hitArray[i].x += moveArray[i];
		moveArray[i] *= eDecay;
		if (hitArray[i].y >= ground.y) {
			hitArray[i].y = ground.y;
		}
		if (Math.abs(player.x - hitArray[i].x) <= pRange && Math.abs(player.y - hitArray[i].y) <= pRange && hitArray[i].x >= player.x && rightAtk == true && leftAtk == false) {
			moveArray[i] += atkPower * multi;
		}
		if (Math.abs(player.x - hitArray[i].x) <= pRange && Math.abs(player.y - hitArray[i].y) <= pRange && hitArray[i].x <= player.x && rightAtk == false && leftAtk == true) {
			moveArray[i] -= atkPower * multi;
		}
	}
}
stage.addEventListener(Event.ENTER_FRAME, stuff);

There about 6 MC's there, player, e1, e2, e3, e4, and ground.

Response to: Can Youz Drawz In Flash? Posted April 7th, 2010 in Game Development

If you want anyone to apply for this, you gotta show work for what YOU can do.

Array/For Loop Problem Posted April 7th, 2010 in Game Development

I have 3 arrays, one with my Enemy MC's (e1, e2, e3, e4), one with a Gravity variable for each enemy, and one more with a movement variable for each of my enemies.

var hitArray:Array = new Array();
var moveArray:Array = new Array("0","0","0","0");
var gravArray:Array = new Array("10","10","10","10");
var i:Number;
hitArray.push(e1);
hitArray.push(e2);
hitArray.push(e3);
hitArray.push(e4);

I also have a for loop, which is supposed to cycle through each enemy, and check various things.

for (i = 0; i < hitArray.length; i++) {
		hitArray[i].y += gravArray[i];
		hitArray[i].x += moveArray[i];
		moveArray[i] *= eDecay;
		if (hitArray[i].y >= ground.y) {
			hitArray[i].y = ground.y;
		}
		if (Math.abs(player.x - hitArray[i].x) <= pRange && Math.abs(player.y - hitArray[i].y) <= pRange && hitArray[i].x >= player.x && rightAtk == true && leftAtk == false) {
			moveArray[i] += atkPower * multi;
		}
		if (Math.abs(player.x - hitArray[i].x) <= pRange && Math.abs(player.y - hitArray[i].y) <= pRange && hitArray[i].x <= player.x && rightAtk == false && leftAtk == true) {
			moveArray[i] -= atkPower * multi;
		}
	}

The first three lines in the loop are just adding the gravity and movement values to the MC's x and y, and also decreasing the movement value. Then theres the ground code, very simple, then the attacking codes, to see if the attack button is pressed while the enemy is in range...blah blah blah.

What happens when I run this (I have other code there as well, such as for the player and keyboard inputs, but only the loop is causing trouble), All the enemies in the array vanish really quickly. After turning the FPS down to 1, I saw they're just moving off the screen really fast. I've also done some testing, and found that the problem only happens when these two lines are run:

hitArray[i].y += gravArray[i];
		hitArray[i].x += moveArray[i];

So yeah. Honestly, I've never really used arrays and for loops together before, so I have no fuckin idea whats going wrong.

PS: If anyone can tell me how to make it so that every time I add an enemy to hitArray, it adds one more value for it in both moveArray and gravArray? That way I can have as many things on there at once as I like, and it does it automatically. Thanks in advance.

Response to: Multiple coordinate checking? Posted April 6th, 2010 in Game Development

Oh wow, hadn't checked this.
Thanks for all the responses, il start on this right now. ^^

Response to: AS3 Question(s) Posted April 6th, 2010 in Game Development

At 4/6/10 02:47 PM, avocode wrote: Transitioning to AS3 here. I'm a total newb. Thanks in advance if you can answer any of these:

1) What is a 'document class'. Is it special? Can't I just make any given class and call it from the timeline?
2) When do you extend MovieClip and when do you extend Sprite?
3) What's up with the import statements (import flash.events.*, etc.)?
4) Should big games have lots and lots of classes or should I try and put more code on the timeline?

I've been using Google but I'm still shaky on these details, so if you can help, I'd really appreciate it.

This is helpful
The first two I can't give a good explanation, but the last two I can.
Those import statements usually aren't necessary, but sometimes are, and are essential if you create your own class. They tell flash to import various bits of code to make it work.
Big games should probably be split up, to keep it more organised, but it is possible to do it in one place, but this isn't recommended.

Response to: Multiple coordinate checking? Posted April 6th, 2010 in Game Development

Maybe.
I haven't used for loops and arrays much, how would you do that? I know you gotta make an array with all the instance names and whatnot in it, then make a for loop (for(i=0;i<total # of things;i++){//stuff}), but I don't know how to cycle through each instance name separately.

Response to: Multiple coordinate checking? Posted April 6th, 2010 in Game Development

Eh, that's the way I already knew, lemme explain what I wanted.
Say there 5 boxes hovering in the air, and the ground is below them. I'd like some code to check weather ANY of them are below

if(anything.y >= ground.y)

then it starts checking their instance names

if(name == obj1){

then it takes appropriate action.

I know other ways of doing this, like that you posted, but They require you to put in each one individually or something, but with this you could simplify it into one code.

But now that I think about it, I'm not sure weather it would be any faster or not.

Response to: Multiple coordinate checking? Posted April 6th, 2010 in Game Development

Bamp


Sorry, didn't have enough space in the title to make it clearer to what I'm asking.
AS3 by the way

Quick question, is there a way to check if anything is below a certain point? Instead of if's checking for each thing individually, is there something to check if anything at all is below a certain point?

Bacon! Posted April 1st, 2010 in General

OMNOMNOMNOMNOMNOMNOMNOMNOMNOMNOMNOM
BACON!

Response to: The Arts Posted April 1st, 2010 in NG News

OMNOMNOMNOMNOMNOMNOMNOM
BAAAAACOOOONNNN

Response to: Guy Fawkes Posted March 26th, 2010 in General

Niether of them right, of course.
We can't tell you who that is. Lurk 4chan for about 5 minutes to find out.

Response to: Guy Fawkes Posted March 26th, 2010 in General

He's your mom.

Response to: Donnie Darko Posted March 26th, 2010 in General

Especially if you're going to shoot them at some point.

Response to: Donnie Darko Posted March 26th, 2010 in General

One of my favourite movies. Don't know why, but everyone in my family pretty much loves it.

And don't worry, after the 4th or 5th time you get all of it. ;)
Response to: Which DS should I get? Posted March 14th, 2010 in Video Games

DS Lite. DSI takes out the slot for advanced games, and the original one is too big.