Typewritting text

Non-platform specific questions.

Typewritting text

Postby Hblade » Tue Dec 20, 2011 5:57 pm

I think I may be able to understand this now. Can someone explain how I can make typing text? I know I could search the forums, but the code would be thrown out all at once. Can someone break down into details how this can be done? I remember a while back I did it but you couldn't "erase" the message. o-o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Typewritting text

Postby lcl » Tue Dec 20, 2011 7:06 pm

I'll explain this to you later today, it's actually really easy :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Typewritting text

Postby SuperSonic » Tue Dec 20, 2011 7:10 pm

I did this once so I can try to explain it to you :D

So first, you need to put a new script in your global code. Inside that script, you need to enter this:
Code: Select all
char message[255]//This is what the text you typed in will be stored as.


Ok, now create an actor and call it something like "DisplayMessage". Now you need to add a Create Actor event and put this in it:
Note: you need to make sure that DisplayMessage is a text actor. You'll see why soon.
Code: Select all
strcpy(message, "");//This will clear the message


Ok now so far, we have a char array called message and when the game starts, it will be empty. Now for the next step. Add a Draw Actor event to you actor and put this in it:
Code: Select all
strcpy(text, message);//This will show the message to you


Now for the hard part (I'll break it down step by step for you. Create a Key Down event for any key, whenever at least one is pressed, and don't do repeat. Inside, put this:
Code: Select all
if(getLastKey() >= 97 && getLastKey() <= 122)

Now you need to understand that getLastKey() will return an int and if the last key was a letter, then the number returned will be as low as 97 and as high as 122. So basically, this if statement checks to see if the last key was a letter.
Now add this:
Code: Select all
{
    strcat(message, getKeyText(getLastKey()));
}

Now this part will add the letter pressed into message. Pretty straight forward right? :P
Next:
Code: Select all
else if(getLastKey() == 8)

8 btw, is the number for backspace :wink:

Now this next part is Gogo's code:
Code: Select all
{
    int i;
    for(i = 0; i < 255; i++)
    {
        if(message[i] == 0)
        {
            message[i - 1 * (i > 0)]=0;
            break;
        }
    }
}

Please don't ask me to explain that, I hardly understand it myself. But that's the code you need^^

Anyways, hope that solved your problem :P

Sonic
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Typewritting text

Postby SuperSonic » Tue Dec 20, 2011 7:11 pm

lcl wrote:I'll explain this to you later today, it's actually really easy :D

Haha, beat you to it XD
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Typewritting text

Postby lcl » Tue Dec 20, 2011 7:20 pm

@SuperSonic: that's text inputting function but what Hblade wanted was typewrite effect (like this one: viewtopic.php?f=4&t=9329&p=64755&hilit=typewrite#p64755), I suppose :D
Anyway, that your code is quite nice, but it still has one flaw; if you press many keys at the time, it lags.
Kinda hard to explain but you'll see it when you type fast.
And btw, Super, instead of 8 you can just write KEY_BACKSPACE, it's predefined to be 8.

@Hblade: I'll start writing now :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Typewritting text

Postby Hblade » Tue Dec 20, 2011 7:30 pm

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

Re: Typewritting text

Postby SuperSonic » Tue Dec 20, 2011 7:30 pm

lcl wrote:@SuperSonic: that's text inputting function but what Hblade wanted was typewrite effect

Oh, my bad :lol:
lcl wrote:Anyway, that your code is quite nice, but it still has one flaw; if you press many keys at the time, it lags.
Kinda hard to explain but you'll see it when you type fast.

Oh, I see what you mean. But the problem can be fixed by upping the fps :D
lcl wrote:And btw, Super, instead of 8 you can just write KEY_BACKSPACE, it's predefined to be 8.

Oh cool. I had no idea. Are there any others like that? :P
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Typewritting text

Postby lcl » Tue Dec 20, 2011 7:34 pm

So, here's how you would make a typewrite effect.
I'm not giving you the whole code, I more likely tell you how to write one :D

You'll need these global variables:
Code: Select all
int counter;
char temp[256], type[256];


Then, in global code, create a void function, name it like typewrite or something and give one parameter, char input[256].
Then, inside the function create integer i.
Do a for loop from 0 to 256 and reset all the cells of 'temp' and 'type'.
Like this:
Code: Select all
temp[i] = NULL;

And after the for loop set counter to 0 and use strcpy to copy input to temp.
Here's all you need in global code. :)

Then, go to your text actors draw actor code and make an if condition and check if counter < strlen(temp).
Inside that condition set type[counter] equal to temp[counter] (that's how you copy single characters!)
And then write counter ++;

After that you'll need to add a sprintf() call to display 'type' on the actors text.

Now you can use your typewrite() function to make it typewrite something.
For example: view - create actor:
Code: Select all
typewrite("Hello! This works! :DD");


And if you wanted to skip the effect, you'd just write use strcpy() to copy temp to type and then set counter equal to strlen(temp).

Ask if there is something you don't understand! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Typewritting text

Postby lcl » Tue Dec 20, 2011 7:36 pm

SuperSonic wrote:
lcl wrote:@SuperSonic: that's text inputting function but what Hblade wanted was typewrite effect

Oh, my bad :lol:

xDD :lol:
SuperSonic wrote:
lcl wrote:And btw, Super, instead of 8 you can just write KEY_BACKSPACE, it's predefined to be 8.

Oh cool. I had no idea. Are there any others like that? :P

The whole list is here: http://game-editor.com/docs/script_reference.htm :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Typewritting text

Postby SuperSonic » Tue Dec 20, 2011 7:44 pm

Awsome dude thanks :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Typewritting text

Postby Hblade » Tue Dec 20, 2011 8:01 pm

Um, so like this? XD
Global:
Code: Select all
int counter;
char temp[256], type[256];
void TypeWrite(char input[256]) {
    int i2
    for(i2=0;i2<256;i2++) {
        temp[i2]=NULL;
        type[i2]=NULL; }
                                }
    counter=0;
    }


Then:
draw actor
Code: Select all
TypeWrite("Message o3o? %d", VARIABLE_HERE);


I need to be able to display variables too xD
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Typewritting text

Postby lcl » Tue Dec 20, 2011 8:03 pm

Dude, don't rush, I see you haven't read the half of my post xD

EDIT: and to display values, you can do:
Code: Select all
char MYTEMP[256];
sprintf(MYTEMP, "message with integer: %i", myInteger);
typewrite(MYTEMP);
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Typewritting text

Postby Hblade » Tue Dec 20, 2011 8:12 pm

lol thanks. Guess I just got too excited.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Typewritting text

Postby Hblade » Tue Dec 20, 2011 8:24 pm

I read it, and I still can't get it to work. I had to change 256 to 800 because my strings are longer than 256. (For this test atleast). here's what I got after reading your post

Code: Select all
int counter;
char temp[800], type[800];
void TypeWrite(char input[800]) {
    int i2;
    for(i2=0;i2<800;i2++) {
        temp[i2]=NULL;
        type[i2]=NULL; }
        counter=0; //Set input to 0 and
    strcpy(input,temp); // Copy input to temp
    }


I had to use "i2" because I have a global variables called i already.

Now, in draw actor (because I have it displaying stats like in this video:
http://www.youtube.com/watch?v=dj5qmX458JI

Code: Select all
char MYTEMP[800];
if(counter<strlen(temp)) {
    type[counter]=temp[counter];
    counter++;

 }
sprintf(text, type);
sprintf(MYTEMP, "Reiko's Level: %d\nReiko's EXP: %d\nTo next level: %d\n\nReiko's Attack: %d\nReiko's Defense: %d\nReiko's Magic: %d\nReiko's Speed: %d\nReiko's Luck: %d", PlayerLEVEL, PlayerEXP, TO_NEXT, PlayerATK, PlayerDEF, PlayerMAG, PlayerSPD, PlayerLUCK);
GetEXPInfo(25, (.90*PlayerLEVEL));
GetStatusInfo((.26*PlayerLEVEL), (.22*PlayerLEVEL), (.15*PlayerLEVEL), (.22*PlayerLEVEL), (.15*PlayerLEVEL));
TypeWrite(MYTEMP);


I got confused somewhere along the way o-o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Typewritting text

Postby lcl » Tue Dec 20, 2011 9:41 pm

You can't have strings with size of 800, 256 is the limit of GE.

Also:
You wrote:
Code: Select all
strcpy(input,temp); // Copy input to temp

that code copies temp to input, so, it clears input.
Ge documentation http://game-editor.com/docs/script_reference.htm wrote:strcpy: Copies the contents of str2 into str1. str2 must be a pointer to a null-terminated string. strcpy() function returns a pointer to str1.
char *strcpy(char *str1, const char *str2);

I think you already knew that :wink:

And also, let's think what you're trying now with your code..
You're using typewrite() in draw actor code, which means that it resets the text again every single frame.
Note that all that typewrite() -function does is reset values and copy the inputted line to temp.

The following part is the one that makes the letter by letter effect:
Code: Select all
if(counter<strlen(temp))
 {
    type[counter]=temp[counter];
    counter++;
}


So, what are you trying to do?
Having it to first typewrite the whole thing and then leave it be and just change the stats?
Because as I asid, now you're starting the typewrite effect from 0 every frame and the result of that is nothing. :lol:
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest