Login | Register

Dialogue

October 7, 2006, 13:14 by Calle
[loading]
-->
<b>Question:</b> Hi all. Hopefull this will be fairly wasy to answer.

What I basically want to do is create two text boxes in my game room. I want a large one at the top and a smaller one at the bottom. I want to be able to type text in the bottom and then, when I hit enter it is deleted from the small box and posted into the big box. Like an Instant Message Chat type thing. How Can I do that? No need to explain how to draw the textboxes, just how to create the code to do that.

Diagram:
<img src="http://gmtutorials.com/files/sampleh.jpg">

Also, I want each thing I type after it is displayed in the big box to be on a new line so...

1. Typing First Thing: Hello
2. Display Hello in the big box
3. clear the small box of text
4. type second thing: how are you
5. display on a new line in the big box
6. clear small box
etc.

any help would be much appreciated! Hope you can understand what i'm trying to say!

<b>Answer:</b> I don't know how used you are with variables and arrays, but I'll just give you some example code that you'll be able to study. It also uses the alarm events:

//Initialize the conversation
line[1] = "Hello";
line[2] = "How are you?";
line[3] = "Are you tired?";
line[4] = "Please don't leave";
line[5] = "Take another glas of Whiskey!";
line[100] = "";


Now, in the textboxes you would write line[i] and line[i-1]. To select which you could use the alarm event. In alarm[0] for an example:

if (string_length(line[i+1])>0) {
i += 1;
alarm[0] = room_speed;
}


Note that you would also need to put this in the create even along the line variable intialization:

i = 1;
alarm[0] = room_speed;


Or, of course, you could start alarm[0] at some later point.

And in draw event, like I have already said indirectly:

draw_text(x,y,line[i]);
draw_text(x,y,line[i-1]);


In case you haven't used alarms before; the value you assign to them decides how often the text changes. room_speed is one second, room_speed*2 is two seconds etc.

You could clear the boxes by having variable go to a line which you have intialized line[x] = "";

<b>Example:</b> http://gmtutorials.com/files/boxexample.gm6

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