-
Quick help with arrays?
This should be pretty easy for you guys. Basically the I want to make it so that if the player hits any of the walls within the walls array, he stops, but putting 'or' in the array doesn't work. Any ideas? This is Actionscript 2 by the way.
Code:
if (Key.isDown(87))
{
_root.hitbox._y = _root.player._y - 10;
this.gotoAndStop("walk");
//Here's the problem
if (!_root.hitbox.hitTest(_root.walls[0 or 1]))
{
this._y -= _root.movespeed;
}
}
-
You can use a compound "if" statement
Code:
if (Key.isDown(87))
{
_root.hitbox._y = _root.player._y - 10;
this.gotoAndStop("walk");
//Here's the problem
if ( (!_root.hitbox.hitTest(_root.walls[0])) || (!_root.hitbox.hitTest(_root.walls[1])))
{
this._y -= _root.movespeed;
}
}
compound is more than one boolean statement - if(boolean || boolean || boolean){
|| means "or"
&& means "and"
-
This didn't work I modified it a bit and got this
Code:
if (Key.isDown(87))
{
_root.hitbox._y = _root.player._y - 10;
this.gotoAndStop("walk");
//Here's the problem
if ( (!_root.hitbox.hitTest(_root.walls[0] || _root.walls[1])))
{
this._y -= _root.movespeed;
}
}
But this only worked for wall 1 (wall[0]). When I tried the code you provided neither worked. I'll attach the .FLA, I'm on Flash CS6 AS2 by the way. Also if anyone can help with the shaky VCAM that would be appreciated.
Topdown RPG.fla
-
Also the code shown is located in the player movieclip. Anyone?
-
Ok so I managed to get this to work:
Code:
if (!_root.hitbox.hitTest(_root.walls[0]) and (!_root.hitbox.hitTest(_root.walls[1])))
But this completely defeats the purpose of the array in the first place. I only used an array because I thought it would make referencing a million different walls at once easier, but now instead of referring to each individual wall I'm referring to each individual value of each wall... Somebody please help me with this I've been trying to figure this out for hours. Absolutely ANY advice helps.
-
So basically I'm trying to condense this:
Code:
if (!_root.hitbox.hitTest(_root.walls[0]) and (!_root.hitbox.hitTest(_root.walls[1]) and (!_root.hitbox.hitTest(_root.walls[2]) and (!_root.hitbox.hitTest(_root.walls[3]) and (!_root.hitbox.hitTest(_root.walls[4]) and (!_root.hitbox.hitTest(_root.walls[5]) and (!_root.hitbox.hitTest(_root.walls[6]) and (!_root.hitbox.hitTest(_root.walls[7]) and (!_root.hitbox.hitTest(_root.walls[8]) and (!_root.hitbox.hitTest(_root.walls[9]) and (!_root.hitbox.hitTest(_root.walls[10]) and (!_root.hitbox.hitTest(_root.walls[11]) and (!_root.hitbox.hitTest(_root.walls[12]) and (!_root.hitbox.hitTest(_root.walls[13]) and (!_root.hitbox.hitTest(_root.walls[14]))))))))))))))))
-
My mistake, I put in "or" when it should have been "and".
You can use a "for loop". A "for loop" repeats the code inside the loop as many times as you specify.
Code:
for (var i = 0; i < _root.walls.length; i++) {
if (!_root.hitbox.hitTest(_root.walls[i])) {
this._y -= _root.movespeed;
}
}
This should loop through _root.walls.length number of times. If _root.walls.length causes an error, replace with a regular number.
I can't test AS2.
-
This didn't work but I think it would if I assigned values to my array properly. This is how I've been doing it:
Code:
var walls:Array = new Array(_root.wall0, _root.wall1, _root.wall2, _root.wall3, _root.wall4, _root.wall5, _root.wall6, _root.wall7, _root.wall8, _root.wall9, _root.wall10, _root.wall11, _root.wall12, _root.wall13, _root.wall14, _root.wall15, _root.wall16, _root.wall17, _root.wall18, _root.wall19, _root.wall20, _root.wall21, _root.wall22, _root.wall23, _root.wall24, _root.wall25, _root.wall26, _root.wall27);
If I don't have this code on every frame it doesn't work... And it takes forever to add new walls. Any suggestions? Also is there a quick way to give my walls instance names?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|