Login | Register

Autowrite text

June 27, 2007, 23:59 by Calle
[loading]
-->
This was a question which was sent to me, and rather than trying to explain to you my task I might as well write it out to you: <i> How can I make a text field and have it type a sentence that I already made up while I'm typing something totally different? Like, I can press any letters on the keyboard but no matter what it\'s gonna type something like, say for example: "I like to go jogging". And it will always type that, for every letter I type no matter what letter it is, it types whatever sentence I put it to type to. I duno if I'm explaning myself?? I'm not familiar with strings at all but I'm also not a beginer in gm but if someone can help me out with this? </i> ... I made an example out of it, but I will also try to do some explaining, as this does use strings...


Create Event:
execute code:

mytext = "Sir Winston Leonard Spencer-Churchill, (30 November 1874 24 January 1965) was a British politician and statesman, soldier in the British Army, orator, and strategist, and is studied as part of the modern British and world history. A prolific author, he won the Nobel Prize in Literature in 1953 for his writings on British and world history.. ## Source: Wikipedia.org";


In this first part I assign the text to a variable. mytext is henceforth a variable containing this string. It will be the content that I write out.

Draw Event:
execute code:

draw_rectangle_color(0,0,room_width,room_height,c_ltgray,c_ltgray,c_gray,c_gray,false);

draw_set_color(c_gray);
draw_set_alpha(0.8);
draw_rectangle(20,40,room_width-20,room_height,false);
draw_text_color(20,5,"Tell me all you know about# Winston Churchill!",c_gray,c_gray,c_black,c_black,1);

draw_set_alpha(1);
draw_set_color(c_black);


This code above here is just some layout stuff that I put together, you don't need to care about. This which I will show you next is the important stuff...

draw_text_ext(25,45,string_copy(mytext,1,string_length(keyboard_string)),-1,room_width-50);

draw_text_ext will write out a string will write out a string at a suiting position, with correct width and separation. The string will be what the user sees and it needs to be as long as what he has written himself. What the user writes is automatically stored in a variable called keyboard_string, which makes this pretty simple. We simply copy as many letters from the variable mytext as keyboard_string consists of. string_length(keyboard_string) is the number of characters the user has input, so now we copy that many characters from mytext, and that will be what we write out: string_copy(mytext,1,string_length(keyboard_string))

<b>Example:</b> Download
Ask any questions by commenting, as always :)

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games