Be a Supporter!

Simple problem - simple fix..?

  • 251 Views
  • 8 Replies
New Topic Respond to this Topic
Guil07
Guil07
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Simple problem - simple fix..? 2009-04-29 12:20:42 Reply

Hey everyone..!

Just reworking the pause menu in my game I'm developing. Here's a dumbed down version of the code I'm using and exactly what my problem is:
http://pastebin.com/m728db5c3

Thanks a bunch,
~Guil


BBS Signature
Fabzilla
Fabzilla
  • Member since: Mar. 24, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Simple problem - simple fix..? 2009-04-29 12:42:58 Reply

if (Key.isDown(80)) {
        if (MenuSS == false) {
        MenuSS = true;
        } else {
        MenuSS = false;
        }
}

//try adding an if keyup function here, dunno how it goes to be honest...
if(keyUp == true){

if (MenuSS == true) {
//Make the menu appear..
} else {
//Make the menu disappear..
}

}

BBS Signature
Guil07
Guil07
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Simple problem - simple fix..? 2009-04-29 12:51:55 Reply

There's my problem.
There is no Key.isUp..

I used to use .isToggled - however Flash Player would sometimes start with .isToggled = true and sometimes it would be false; depending on if you had pressed it before making Flash Player the focus of a browser..

~Guil


BBS Signature
Guil07
Guil07
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Simple problem - simple fix..? 2009-04-29 12:56:23 Reply

I've been suggested this a couple times:

if (Key.isDown(80) && !pressed) {
		pressed = true;
		if (MenuSS == true) {
			MenuSS = false;
		} else {
			MenuSS = true;
		}
	} else {
		pressed = false;
	}

However the same thing happens..


BBS Signature
ColdLogic
ColdLogic
  • Member since: Nov. 12, 2003
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to Simple problem - simple fix..? 2009-04-29 13:05:23 Reply

i had this problem, its easy, set a timer variable to say like 50 when the button is pressed.
in your main code simply check if its above 0 and if it is subtract one per frame.
when checking if the button is pressed also check if that variable is above 0, if its 0 alow the button to register and bring up or bring down the pause menu.

hope this makes sense. but ive used it before lots.

ColdLogic
ColdLogic
  • Member since: Nov. 12, 2003
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to Simple problem - simple fix..? 2009-04-29 13:08:57 Reply

if (Key.isDown(80) && Menutimer == 0) {
        Menutimer = 50;
        if (MenuSS == false) {
        MenuSS = true;
        } else {
        MenuSS = false;
       }
}
 
if(Menutimer > 0) {
         Menutimer--;
}


if (MenuSS == true) {
//Make the menu appear..
} else {
//Make the menu disappear..
}
Guil07
Guil07
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Simple problem - simple fix..? 2009-04-29 13:09:54 Reply

Thanks, I was considering a timer.. Maybe it's simpler.

Using Key.isToggled was perfect except that you can't set whether or not the key is toggled to true or false at the beginning of playback..

I decided to change it because sometimes when you first click into the Flash Player and thus put it in focus, sometimes Key.isToggled would be true - and sometimes false.. So I'd end up with the pause menu jumping up the instant you click into the game.

~Guil


BBS Signature
Doomsday-One
Doomsday-One
  • Member since: Oct. 28, 2005
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Simple problem - simple fix..? 2009-04-29 13:11:25 Reply

For cases where you want to test whether a key is up or down, you just need to test if the key is down.
Key.isDown(80) works as a true/false variable. Putting '== false' afterwards (or an exclamation mark beforehand, however you want to do it) runs the code if it ISN'T down.

However, don't bother with that this time, because you just need an 'else' statement.

Call it background reading
if (Key.isDown(80)) {
	if (keyheld == false) {
		// checks a variable called 'keyheld', and only runs the code if it is false
		keyheld = true;
		// changes keyheld to true, meaning the code does not repeat until it is changed back
		if (MenuSS == false) {
			MenuSS = true;
		} else {
			MenuSS = false;
		}
	}
} else {
	// i.e. if the key is NOT down
	keyheld = false;
	// changes keyheld back to false
}

So, when the key is first pressed, it changes a variable to say 'true'. Then, if it is held, it doesn't run the code again, because that variable is 'true', and it has been told not to run the code if it is true.
When the key isn't down, it changes that variable to 'false', meaning the next key press makes the code run again.

This differs from your new 'suggestion', because your suggestion has a small problem.
The 'else' block of code runs if the key is not down, OR your variable is 'true'. So it keeps changing the variable back to false whenever it is true.


Doomsday-One, working on stuff better than preloaders. Marginally.

Guil07
Guil07
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Simple problem - simple fix..? 2009-04-29 13:31:13 Reply

That's brilliant, Doomsday-One!

Works like a charm, thank you; I really appreciate it.
Simple explanation with example, thanks again..!

~Guil


BBS Signature