dMZX Forums: Keymapping - Can numpad keys be used? - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Keymapping - Can numpad keys be used?

#1 User is offline   OhGoodShepherd 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 29-January 16

Posted 31 January 2016 - 07:48 AM

First post, pre-apologies if this is the wrong area to ask in or a poorly formed question:

I would like to be able to move diagonally in a top-down game. I found code for diagonal movement in one of the Encyclopedia Games and am attempting to modify the code of it by changing keyq to key# where the # = the keyboard key map for the numpad 7 - I located this chart: http://www.digitalmz...m/keycodes.html and attempted making it key71 or key263 with no effect. I made use of a simple bit of robotics learned from a tutorial video (very thankful for these!) to display on screen * "&key_pressed&" which actually gave me numpad 7 as 55 - but when I tried 55 I had no luck and going back and running that robot again gave me a result of 278! In the Misc Counters help I saw mention of 23(if I recall) being space, 9 being Tab and 13 being Enter. I attempted these and key9 did not make Tab work but made the 9 on the number row work! (Of course!) ... any thoughts or advice would be appreciated! Perhaps I am doing something wrong and/or num pad keys are not supported? Thanks!

This post has been edited by OhGoodShepherd: 31 January 2016 - 07:49 AM

0

#2 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,936
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 31 January 2016 - 09:05 AM

Okay, there's a couple of things here:

  • Very old Robotic code, like the MZX Encyclopedia code you're looking at, typically use : "key?" labels for detecting keys (other than space, del and arrow keys) because that was the only way of detecting those keys at the time. You can now use the "key#" counters, where # is an actual number, to test the value of a scancode.
  • The reason you got both 55 and 278 is because key_pressed (and the : "key?" labels) uses the translated version of the scan code. The numpad keys have two options depending on whether or not the numlock key is on. If the numlock key is off the numpad keys function as home, end, pageup, pagedown and the cursor keys, which is why you got 278 (because it corresponds to the home key). If the numlock key is on they correspond to numbers, which is why you got 55 (because it corresponds to the 7 key).
  • If you want a : "key?" label to work with the tab key you need to use a tab character like this: : "key\t".
  • You can use the : "key?" labels to detect the numpad keys when the numlock key is on, just by using the numbers (e.g. "key7" "key9" "key1" "key3") - however, you won't be able to use these labels when the numlock key is off.
  • The key_code counter (create a robot with * "&key_code&" to test these codes) is different because it's pre-translation - so you will get 71 whether the numlock key is on or not. However, it means you need to use the "key#" counters instead.


The "key#" counters are thankfully easy to use because you can use the numbers. (e.g. check the value of "key71" to see if the player is pressing the top left numpad key)

Here's a simple example:

MainRobot
: "loop"
if "key71" = 1 "NorthWest"
if "key73" = 1 "NorthEast"
if "key79" = 1 "SouthWest"
if "key81" = 1 "SouthEast"
wait 1
goto "loop"
: "NorthWest"
send "SecondRobot" "n"
move player w
goto "loop"
: "NorthEast"
send "SecondRobot" "n"
move player e
goto "loop"
: "SouthWest"
send "SecondRobot" "s"
move player w
goto "loop"
: "SouthEast"
send "SecondRobot" "s"
move player e
goto "loop"

SecondRobot
end
: "n"
move player n
end
: "s"
move player s
end

Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#3 User is offline   OhGoodShepherd 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 29-January 16

Posted 31 January 2016 - 05:44 PM

Thank you for the reply!

I made a quick board using your code but was unable to get it working correctly.

I am not sure if I did something incorrectly or not but when I test it Num7 and Num1 move the character left and Num9 and Num3 move the character right - from my minimal understanding it looks like it should move me one direction, then the second robot move me the other direction needed to emulate diagonal movement but - no such luck, probably something on my end though!

My other concern is that your example might not allow me to move on the diagonal through a small opening, though when I was not able to test that yet.

I made a butchered effort to combine the Encyclopedia code with what you provided and changed:

: "NorthWest"
send "SecondRobot" "n"
move player w

to

: "NorthWest"
rel to player
put player at -1 -1

It seems to be working and I believe I see how I can map all of the numpad keys now using this method though I am not sure if what I am doing really makes sense or is the best way to go about it - so far, so good, really loving MegaZeux and thankful for the community!
0

#4 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,936
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 31 January 2016 - 10:31 PM

My guess is that you didn't name the second robot SecondRobot, which is important as MainRobot uses that name to communicate with it. The problem with 'put player # #' is that it will cause the player to travel through walls etc. You could add a check to ensure that nothing solid is in the way, but this is more complicated than it sounds as there are many types that can be walked over and many types that can't. Besides, even if you did implement such a check, you would not be able to : "touch" robots, signs etc. or pick up items with diagonal movement. (Again, you can implement most of these things, but it's overly complex to do.) This is why move player [dir] is the better approach (and the one the Encyclopedia used) - with the slight downside that move player [dir] is a cycle ending command (it's effectively followed by an implicit 'wait 1') which means two robots need to use it to get diagonal movement.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#5 User is offline   OhGoodShepherd 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 29-January 16

Posted 31 January 2016 - 11:23 PM

I ended up making this:

: "loop"
if "key71" = 1 then "GoNW"
if "key72" = 1 then "GoN"
if "key73" = 1 then "GoNE"
if "key75" = 1 then "GoW"
if "key77" = 1 then "GoE"
if "key79" = 1 then "GoSW"
if "key80" = 1 then "GoS"
if "key81" = 1 then "GoSE"
wait for 1
goto "loop"
: "GoNW"
rel to player
put player at -1 -1
* "NORTH WEST"
goto "loop"
: "GoN"
move player to NORTH
goto "loop"
: "GoNE"
rel to player
put player at 1 -1
goto "loop"
: "GoE"
move player to EAST
goto "loop"
: "GoW"
move player to WEST
goto "loop"
: "GoSE"
rel to player
put player at 1 1
goto "loop"
: "GoS"
move player to SOUTH
goto "loop"
: "GoSW"
rel to player
put player at -1 1
goto "loop"


it does indeed suffer from those problems you mentioned! :(

Good learning experience though.

Also, you are correct - I did not name the second robot - going to poke at that now.

Thank you.
0

#6 User is offline   Wervyn 

  • I can see you
  • Group: DigiStaff
  • Posts: 1,855
  • Joined: 24-December 00
  • Gender:Male
  • Location:Caras Galadhon

Posted 01 February 2016 - 07:46 PM

Kicking this over to Robotic Talk, carry on. You know, if it hasn't already been answered to your satisfaction.
To lie is to change the truth.
..Ignorance is to be unaware of the truth.
....Incompetence is to be unable to grasp the truth.
......And escape is to run away from the truth.
It is useless to run, since the truth is right next to you.

-Wervyn
0

#7 User is offline   GetDizzy 

  • Touch Fuzzy.
  • Group: DigiStaff
  • Posts: 3,564
  • Joined: 22-November 01
  • Gender:Other
  • Location:MA

Posted 04 February 2016 - 02:59 PM

Good to see someone new learning MZX. Don't have much to say on this issue (seems like you've figured it out already, really), but welcome to our forums :(
- Your Jumpy Neighborhood Admin

<@Tixus> Anyway, I set the year to 1988 for some reason.
<@Tixus> And set the microwave to run for a minute and 28 seconds.
<@Tixus> But it failed to send me back in time, and I was disappointed.
<Insidious> Tixus accidentally microwaved the 80s
<Insidious> that is my takeaway from this
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users