Android How To Set Virtual Key To a LETTER KEY.

F

Frederick Foote

Guest
Im a bit rusty, been over a year since I worked on my game and can't figure this out. I tried

global.XZ = virtual_key_add(ControlX-32, ControlY-100, 64, 64, (ord("X")+ord("Z")));
global.X= virtual_key_add(ControlX-32, ControlY+40, 64, 64, ord("X"));
global.Z = virtual_key_add(ControlX-106, ControlY-30, 64, 64, ord("Z"));
global.Jump = virtual_key_add(ControlX+40, ControlY-30, 64, 64, vk_space);

but only Jump worked because it's a simple vk command. How do I use VK for a letter?​
 
T

The Shatner

Guest
Hey Frederick!
Try using something like:
Code:
global.XZ = virtual_key_add(ControlX-32, ControlY-100, 64, 64, (keyboard_check(ord("X"))&&(keyboard_check(ord("Z")));
global.X= virtual_key_add(ControlX-32, ControlY+40, 64, 64, keyboard_check(ord("X")));
Try using keyboard_check, keyboard_check_pressed or keyboard_check_released (depending on your necessity). Otherwise it may not return true when the button is pressed.
Another alternative would be to do the following:
Code:
STEP EVENT
if (keyboard_check(ord("Z")) {
      zee = true;
}

DRAW GUI EVENT
global.Z= virtual_key_add(ControlX-32, ControlY+40, 64, 64, zee);
This could work because, theoretically, the virtual key checks to see if the last argument is true.
Also, check if the Virtual Key is set to be drawn in the "Draw GUI" event. Otherwise they get buggy.

You should also know that there used to be a known bug in GM that made it quite hard (not to say impossible) to use keys other than the vk_ ones in Virtual Keys. I'm not sure they have fixed it, although it's been a while since the bug was reported.

Well, I'm no expert in Virtual Keys, but I'd try that if I was angrily debugging...

Tell us what happened later!
Cheers!
 
W

Wraithious

Guest
I believe you have to use single quotes around the capital letter- ord( ' Z ' )
 
F

Frederick Foote

Guest
That didn't work but I think my issue is more complex. My VK for letter Z works on a title screen of my game but not in my game level. First I have my Virtual Keys set on another object and it uses this code:

global.Z= virtual_key_add(ControlX-52, ControlY-16, 32, 33, ord("Z"));
global.Jump = virtual_key_add(ControlX+20, ControlY-16, 32, 33, vk_space);​

The only difference is in how they are used.

Main Screen :
Select = keyboard_check_pressed(ord("Z"))​


Game Level:
Punch = keyboard_check_pressed(ord("Z"))
PunchRelease = keyboard_check_released(ord("Z"))
PunchHold = keyboard_check(ord("Z"))

MoveJump = keyboard_check_pressed(vk_space)​

Because the code works on the main screen but not the game level I do not think it is the virtual_key_add command but something to the punch code. Also note that the Jump virtual key works fine.

So to wrap it all Up. I used the top code in a separate object to control my virtual keys. The code works in the Main Screen but not the game level. Jump works on the game level just not the punching. I assume it has to do with using all three of the codes but it works fine on PC version.
 
F

Frederick Foote

Guest
NVM ALL....Im just an A**hole. I forgot my character only punches after you switch to combat mode(which i didnt make a button for) Original code was A+...Carry on LOL
 
Top