Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1401678 Posts in 67940 Topics- by 61496 Members - Latest Member: Lankar5

July 06, 2022, 11:42:48 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)AGHHHH HELP THIS IS DRIVING ME NUTS (solved)
Pages: [1]
Print
Author Topic: AGHHHH HELP THIS IS DRIVING ME NUTS (solved)  (Read 2812 times)
Hinchy
Level 3
***



View Profile WWW
« on: May 23, 2008, 12:53:43 PM »

Okay. I'm developing a game. Earlier today, the character jumped. Now, it doesn't. I've managed to get it down to a conflict - the game is telling itself to set the variable canJump to true and false at the same time. However, I cannot for the life of me figure out how to fix it. Here's the code:

Code:
if ((_root.walls.ground.hitTest(_x,_y+_height,true)) or (_root.walls.ground.hitTest(_x+(_width/2),_y+_height,true)) or (_root.walls.ground.hitTest(_x+_width,_y+_height,true))) {
while ((_root.walls.ground.hitTest(_x,_y+_height+1,true)) or (_root.walls.ground.hitTest(_x+(_width/2),_y+_height+1,true)) or (_root.walls.ground.hitTest(_x+_width,_y+_height+1,true))) {
_y--;
jumpCount = 0;
jumpSpeed = jumpSpeedReset;
}
if (!(remote.isDown(WiiRemote.BUTTON_2))) {
canJump = true;
canYMove = true;
}
grav = 0;
} else {
canJump = false;
}

it shouldn't set canJump to false and true at the same time, yet it does! does anyone have an answer for me?
« Last Edit: May 23, 2008, 04:26:55 PM by Zachary Hinchliffe » Logged
Guert
Level 10
*****



View Profile WWW
« Reply #1 on: May 23, 2008, 02:19:42 PM »

How about if you explain to us your logic behind what your are doing? Like I'm doing this because of that and then this to do that... It might help giving you an answer... Maybe. Wink
Logged

joshg
Level 4
****



View Profile WWW
« Reply #2 on: May 23, 2008, 02:23:52 PM »

Judging from what you've said, it's probably running through this if block more often than you're expecting.  Which means that showing us the if block itself probably won't help at all because the problem will be in whatever code is causing this to run in the first place.

Stop looking at this block of code and start looking at how often it's being hit, and when and why.
Logged

these are from an actual radio shack in the ghetto
Hinchy
Level 3
***



View Profile WWW
« Reply #3 on: May 23, 2008, 02:32:02 PM »

Stop looking at this block of code and start looking at how often it's being hit, and when and why.

alright. while i do that, just in case any of you want to look, here's the entire code:

Code:
onClipEvent (load) {

///////////////
// constants //
///////////////
crawlSpeed = 5;
walkSpeed = 8;
jumpLimit = 18;

/////////////////////
// initializations //
/////////////////////
health = 100;
grav = 0;
jumpCount = 0;
canWalk = false;
_root.gamePaused = false;
canYMove = true;
jumpSpeedReset = 13;
jumpSpeed = jumpSpeedReset;
_root.zKey = "";
_root.xKey = "";
_root.cKey = "";
_root.vKey = "";
_root.spaceBar = "jump";

////////////////////
// Wii Remote API //
////////////////////
import com.wiicade.*;
var remote = Wii.getRemote(0);
KeyboardController.setKeyMapping(WiiRemote.BUTTON_2,Key.SPACE);
KeyboardController.setKeyMapping(WiiRemote.BUTTON_B,86);
remote.setRotated(true);
}

onClipEvent (enterFrame) {

////////////////
// health box //
////////////////
health1 = health%1;
health2 = health%2;
health3 = health%3;
if (health3>0) {
_root.hud.hundredsdigit.gotoAndStop(health3);
} else {
_root.hud.hundredsdigit.gotoAndStop(10);
}
if (health2>0) {
_root.hud.tensdigit.gotoAndStop(health2);
} else {
_root.hud.tensdigit.gotoAndStop(10);
}
if (health1>0) {
_root.hud.onesdigit.gotoAndStop(health1);
} else {
_root.hud.onesdigit.gotoAndStop(10);
}

//_root.gamePaused stops everything when game is paused
if (!(_root.gamePaused)) {
//////////////////////////
// x movement/collision //
//////////////////////////

//walking left
if ((remote.isDown(WiiRemote.BUTTON_LEFT)) && (!(_root.walls.leftWall.hitTest(_x, _y, true)) && !(_root.walls.leftWall.hitTest(_x, _y+(_height/2), true)) && !(_root.walls.leftWall.hitTest(_x, _y+_height, true)))) {
if (walk == false) {
_x -= crawlSpeed;
} else {
_x -= walkSpeed;
}
}

//walking right
if ((remote.isDown(WiiRemote.BUTTON_RIGHT)) && !(_root.walls.rightWall.hitTest(_x+_width, _y, true)) && !(_root.walls.rightWall.hitTest(_x+_width, _y+(_height/2), true)) && !(_root.walls.rightWall.hitTest(_x+_width, _y+_height, true))) {
if (walk == false) {
_x += crawlSpeed;
} else {
_x += walkSpeed;
}
}

//wall buffers
if (_root.walls.leftWall.hitTest(_x, _y+(_height/2), true)) {
while (_root.walls.leftWall.hitTest(_x-1, _y+(_height/2), true)) {
_x++;
}
}
if (_root.walls.rightWall.hitTest(_x+_width, _y+(_height/2), true)) {
while (_root.walls.rightWall.hitTest(_x+_width+1, _y+(_height/2), true)) {
_x--;
}
}

//////////////////////////
// y movement/collision //
//////////////////////////

//ceiling buffer - if too far in ceiling, pushes out
i = 0;
while (i<_width) {
if (_root.walls.ceiling.hitTest(_x+i, _y, true)) {
while (_root.walls.ceiling.hitTest(_x+i, _y-1, true)) {
canYMove = false;
_y++;
}
}
i++;
}

//mid-air falling
if (!(_root.walls.ground.hitTest(_x+(_width/2), _y+_height+1, true))) {
_y += grav;
grav += 2;
}

//ground collision/buffer, also enables jump when 2/Space is not pressed
if ((_root.walls.ground.hitTest(_x, _y+_height, true)) or (_root.walls.ground.hitTest(_x+(_width/2), _y+_height, true)) or (_root.walls.ground.hitTest(_x+_width, _y+_height, true))) {
while ((_root.walls.ground.hitTest(_x, _y+_height+1, true)) or (_root.walls.ground.hitTest(_x+(_width/2), _y+_height+1, true)) or (_root.walls.ground.hitTest(_x+_width, _y+_height+1, true))) {
_y--;
jumpCount = 0;
jumpSpeed = jumpSpeedReset;
}
if (!(remote.isDown(WiiRemote.BUTTON_2))) {
canJump = true;
canYMove = true;
}
grav = 0;
} else {
//disables jump in mid-air
canJump = false;
}

//jump from ground
if ((canJump) && (remote.isDown(WiiRemote.BUTTON_2)) && (jumpCount == 0) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true))) {
_y -= jumpSpeed;
jumpCount += 1;
}
//continuing jump in midair
if (!(canJump) && (canYMove) && (remote.isDown(WiiRemote.BUTTON_2)) && (jumpCount>0) && (jumpCount<jumpLimit) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true))) {
_y -= jumpSpeed;
jumpCount += 1;

//stopping jump after letting go of 2/Space
} else if (!(canJump) && (canYMove) && !(remote.isDown(WiiRemote.BUTTON_2)) && (jumpCount>0) && (jumpCount<jumpLimit) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true))) {
_y -= jumpSpeed;
jumpSpeed -= 3;

//stopping jump when hit ceiling
} else if (((_root.walls.ceiling.hitTest(_x+(_width/2), _y-jumpSpeed, true)) or (_root.walls.ceiling.hitTest(_x, _y-jumpSpeed, true)) or (_root.walls.ceiling.hitTest(_x+_width, _y-jumpSpeed, true)))) {
canYMove = false;
jumpSpeed = 0;
}
////////////////
// walk/crawl //
////////////////

//sets walk if possible
if (remote.isDown(WiiRemote.BUTTON_B) && (canWalk)) {
if (!(_root.walls.ceiling.hitTest(_x, _y-25, true)) && !(_root.walls.ceiling.hitTest(_x+(_width/2), _y-25, true)) && !(_root.walls.ceiling.hitTest(_x+_width, _y-25, true))) {
walk = true;
}
} else {
walk = false;
}

//walking changes
if (walk) {
_xscale = 100;
_yscale = 150;
jumpSpeedReset = 20;
performOnce = true;
if (performOnce2) {
performOnce2 = false;
_y -= 25;
}
} else {
_xscale = 150;
_yscale = 100;
jumpSpeedReset = 13;
if (performOnce) {
performOnce = false;
_y += 25;
}
performOnce2 = true;
}
/////////////////
// other stuff //
/////////////////

//makes boundary movieclips invisible
_root.walls.ground._visible = false;
_root.walls.leftWall._visible = false;
_root.walls.rightWall._visible = false;
_root.walls.ceiling._visible = false;

//hud stuff
if (canWalk) {
_root.vKey = "walk";
}
}
}
« Last Edit: May 23, 2008, 04:13:02 PM by Zachary Hinchliffe » Logged
joshg
Level 4
****



View Profile WWW
« Reply #4 on: May 23, 2008, 03:31:30 PM »

I looked at it a bit, but with minimal commenting and no access to the .fla it's kind of hard to follow what you're doing.

What did you mean by a conflict where it's trying to set canJump to both true and false at the same time?  There's no way it's literally trying to do both simultaneously - do you mean that it's being set twice in one frame?

Also, that block with the "while (...) { _y--; ...etc }" confuses the heck out of me.  Are you doing some kind of insta-fall-down where the character just drops down to the ground immediately?
Logged

these are from an actual radio shack in the ghetto
Hinchy
Level 3
***



View Profile WWW
« Reply #5 on: May 23, 2008, 03:45:49 PM »

Also, that block with the "while (...) { _y--; ...etc }" confuses the heck out of me.  Are you doing some kind of insta-fall-down where the character just drops down to the ground immediately?

actually, what it does is if you're embedded too far into the ground it automatically pushes you up to the surface.

here's the FLA (flash 8), with Wii Remote API included: http://tract.isamedia.org/tract.zip
(EDIT: download again if you've already downloaded, I added some basic commenting)

all the important (and troublesome) code is currently in the blue square (instance name "smithy").

EDIT #TWO: Wow. I just rewrote that block of code and now it works. Dunno what fixed it, but can't argue with the results. This topic can be locked/ignored.
« Last Edit: May 23, 2008, 04:26:41 PM by Zachary Hinchliffe » Logged
X-Tender
Level 1
*



View Profile WWW
« Reply #6 on: May 25, 2008, 02:56:11 AM »

Hi, Is this your first Flash game you make? I'am just currious because you're mixing AS1 and AS2, you're code is kinda messy Smiley
When you need some more detailed help in the Future you can PM me or post here again too Smiley
Logged

Hinchy
Level 3
***



View Profile WWW
« Reply #7 on: May 26, 2008, 05:30:11 PM »

Hi, Is this your first Flash game you make? I'am just currious because you're mixing AS1 and AS2, you're code is kinda messy Smiley
When you need some more detailed help in the Future you can PM me or post here again too Smiley
it's my second, but it's the first one I'm doing without help from someone else (my first game, Key To Adventure, was almost completely rewritten by a friend)
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic