Android [SOLVED] Help w/keyboard_check_pressed & virtual keys

P

PixelProgrammer

Guest
So basically, I have a game where you buy upgrades with money. Pretty simple but since it's on android to "confirm" your purchase I used virtual keys. So the problem all the upgrades are bought at once if you have enough money. So an example code is:

if (upgrade == 1) {
if (keyboard_check_pressed(ord("p"))) {
if (cash >= 10000) {
upgrade = 2;
cash -= 10000;
}
}
}

if (upgrade == 2) {
if (keyboard_check_pressed(ord("p"))) {
if (cash >= 25000) {
upgrade = 3;
cash -= 25000;
}
}
}
if (upgrade == 3) {
if (keyboard_check_pressed(ord("p"))) {
if (cash >= 100000) {
upgrade = 4;
cash -= 100000;
}
}
}

Now instead of having to click the buy button each time (which is a virtual key), if you click it once and have enough money all upgrades will be bought instantly. The keyboard_check_pressed acts like keyboard_check.

I'm very sorry if this is really confusing, I'm doing my best to explain the issue, and if you need the game maker project file just ask.
Thanks for any help :)
 
T

TDSrock

Guest
Here is a reason why you should NOT hard-code your input you like you are.

You should first off declare that keyboard_check_pressed(ord("p")) to be the same as a variable, that makes things quite a bit neater.
Code:
upgradeButton = keyboard_check(ord("p"));
Now I've kept in the same issue on this one. How do you think gm handles "pressed" as opposed to "down".
The keyboard simply returns only down through the IO(as far as I recall)

Here's the basic idea.
Code:
set released to false
set pressed to false
if button is not down and down is  true{
   set released to true
}

if the button is down and down is not true{
   set down to true
   set pressed to true
} 

if the button is down{
   set down to true
} else { 
   set down to false
}
Now thats just a quick run through and I might have made a mistake in this quick gloss over.
 
P

PixelProgrammer

Guest
So I'm a little confused as to what you're saying, is the bottom code you provided still flawed like mine? Because you said that "Now I've kept in the same issue on this one". But if I'm just being silly and miss-reading that I understand what the code is saying, just not how to implement it into my code. Also I will remember to organize my code by not hardcoding.
thanks
 
P

PixelProgrammer

Guest
Wow thanks so much TheouAegis, also thanks for helping me understand the problem TDSrock.
 
T

TDSrock

Guest
Wow thanks so much TheouAegis, also thanks for helping me understand the problem TDSrock.
The bottom code is the core idea on how they handle key_pressed key_down and key_released. All they get from the keyboard is true or false, but through checking what pressed was the previouse frame you can see if the value was freshly pressed or if it was already held. The core idea I jotted down in the second code-block of how the implementation of it COULD look like.
 
Top