Only input numbers 0-9 and append blinking cursor!

You must understand the Game Editor concepts, before post here.

Only input numbers 0-9 and append blinking cursor!

Postby Hblade » Fri Sep 11, 2009 3:28 am

Hi guys, i found a way to ONLY allow the text to input numbers, meaning you can only put numbers in textInput, also you can append a blinking character to it! here's the code.

Code: Select all
int focus;
int framecount;

void inputNumbers(int maxnum)
{
    char *key=GetKeyState();
    if (focus == 1)
    {
    if (key[KEY_0] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "0");
    }
    if (key[KEY_1] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "1");
    }
    if (key[KEY_2] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "2");
    }
    if (key[KEY_3] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "3");
    }
    if (key[KEY_4] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "4");
    }
    if (key[KEY_5] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "5");
    }
    if (key[KEY_6] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "6");
    }
    if (key[KEY_7] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "7");
    }
    if (key[KEY_8] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "8");
    }
    if (key[KEY_9] == 1 && strlen(text)<maxnum)
    {
        strcat(text, "9");
    }
    if (key[KEY_BACKSPACE] == 1 && strlen(text)>0)
    {
        strcpy(&text[strlen(text)-1], "");
    }
    }
}
void AppendBlink()
{
    framecount++;
    if (framecount == 12)
    {
        transp = 1;
    }
    if (framecount == 24)
    {
        transp = 0;
        framecount = 0;
    }
}




=]How to use[=
In order to use this, click Add - Key Down - Any key(by right clicking), then putting in inputNumbers(Max numbers), where Max numbers is the maximum ammount you can type. Remember, you have to set the focus variable to 1 before you can type.

For the blinking append, make an actor, click Add - Draw actor - Script Editor and type in AppenBlink();, then type x = "input actor".x + "input actor".width. For example:

x = msg.x + msg.width;

msg is the actor I made who is inputting the numbers. Now put y = "input actor".y;. For example

y = msg.y;

Enjoy
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4345
Joined: Fri Dec 08, 2006 11:14 pm
Score: 167 Give a positive score

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 0 guests