• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

detect any keyboard press of a special kind (numpad, etc)

Didjynn

Member
Hello everyone, I'm not english so I'm sorry if the title isn't clear, I did my best.

I was wondering if there is any option in game maker (and if not maybe could it be a nice feature) to detect only or authorize only a part of the keyboard.

For example, if I want the player to enter a number composed only password, I would like to write on the screen only the numbers the player write but I want to write nothing if he presses a letter. For that do I really need to check each of the keyboard 1, 2, 3... and numpad 1, 2, 3... or is there a way to tell "any letter" or "any numpad number" ?
 
T

tserek

Guest
str = string_digits(keyboard_string);
// stuff here..
keyboard_string = str;

or more simple..
keyboard_string = string_digits(keyboard_string);
 

Didjynn

Member
Hello, thank you for this very fast answer. I feel a little stupid now but who doesn't ask doesn't learn.
If I can ask one more question, how can I extract the value I type ? Because this code isn't working :
if(keyboard_string <5) text = keyboard_string;
 
T

tserek

Guest
Asking is always good choice to get answers, that's why forum is here :) If i'm understood you'd like to also limit keyboard string or text length to 5?
Code:
keyboard_string = string_copy(string_digits(keyboard_string),1,5);

if keyboard_string = string(pass)
{
 // stuff ?
}
 
Last edited by a moderator:

Didjynn

Member
Hi, not the length I already have something for this.

In fact, I am making options for the game, it's a pong game and I want to choose the speed of the ball, the number of balls...

So I have options in an array :
Code:
menuText[1,6] = "Number of Balls"
menuText[1,7] = "Ball Speed"
menuText[1,8] = "Victory Points"
Some of the options can have bigger number than others (some from 1 to 8, others from 1 to 10, others from 50 to 300...). For the length I'm using this in a "press any key" event :
Code:
if (global.inputLimit > 0) && (string_length(keyboard_string) > global.inputLimit) {
          keyboard_string = string_digits(keyboard_string);
          keyboard_string = string_copy(keyboard_string, 1, global.inputLimit);
}
(I don't know if it's really clean but it's working with the code you write to me. If I try to modify things by myself it's not working anymore, I used this tutorial to make it because programming is not my best part : http://site.chronic667.com/gm/tutorials/Tutorial%20-%20Input%20Box.html)

So I have many problems with this. I have an area where I can write numbers and 2 arrows, one to increment, the other to decrement but decrement from 200 to 100 takes a long time so it's better if I can directly write numbers too. The purpose is to give to the global variables the value I'm entering here.
Code:
if (menuSelected = 6) {
        text = "It's time to know if fun is protportionnal to te number of balls on the screen";
        global.mini = 1;
        global.maxi = 9;
        global.inputLimit = 1;
        changeVar = global.numBalls;
      }//number of balls
      if (menuSelected = 7) {
        text = "If you change the ball speed, think about the player speed too";
        global.mini = 2;
        global.maxi = 8;
        global.inputLimit = 1;
        changeVar = global.ballSpeed;
      }
mini is the minimum value, maxi the maximum value (or should be it's nor really working for now).
global.inputLimit = 1; give the length of the string I can enter in the writing area (this one is working, alleluia !)
I hope changeVar can BECOME another variable like in AS3 and not only have his value. The purpose is with a selected part of my array (that I'm using for my menu and option menu) to give the value in the writing area to the variable I need and I know no other way to do that.
I mean, depending of which option I am selecting, I need to change global.speedBall or numberPlayers, etc. So if I enter 2, I need the variable numberPlayers to be 2, etc.

Thank you for your time, sorry for all this text.
 
Last edited:
Top