Login | Register

Chat system using mplay

July 22, 2006, 12:38 by Calle
[loading]
-->
This article will not explain how to make a standard chat, such as the one Mark Overmars do in his tutorial. I will only explain the mplay part of it, and I will use a new method. This method has several advantages, such that it is excellent for server based systems, easy to set up, fast and also saves all historic. In difference to Overmars’ system this uses mplay_data and not a single message!

<div style="clear: both;">First we need to establish a connection, if I would just want to test it over LAN, I could use my auto-select host script, which is described in another article:
mplay_init_tcpip(get_string("Please enter your IP (empty for LAN):","";))
if (mplay_session_find()>0) {
mplay_session_join(0,"client";);
global.host = false
room_goto(room1);
}
else {
mplay_session_create("game",2,"host";);
global.host = true
room_goto(room1);
}
</div>

Otherwise I might want to connect to a server, so I always do like this:
mplay_init_tcpip(global.myserverip);
if (mplay_session_find()>0) {
mplay_session_join(0,"client";);
global.host = false
room_goto(room1);
}
else {
show_message(“Server problem, please try again later”);
}


Whatever I do when I finally get a connection it is time to move on. As this system uses data stacks I need to figure out what data stacks I do not need. For an example my game might already use the first 150 data stacks, so I couldn’t use them, say this is the case. So this might be my creation code (for the host):

data_stack_start = 151
if (global.host==true) {
mplay_data_write(data_stack_start,1);
mplay_data_write(data_stack_start+1,”Server is set up. Welcome.”);
}


As you can see, as long as you initialize the global.host variable correctly client and host may use the same piece of code. For input further info (from user, e.g. when he presses enter), like keyboard_string, use this code:

archive_size = mplay_data_read(mplay_data_start);
mplay_data_write(data_stack_start+archive_size,global.myname+”:
+keyboard_string);
mplay_data_write(mplay_data_start,archive_size+1);


And this will add a new piece of code to the next data stack. Keyboard_string was just an example though. The only thing left is to draw the text:

draw_lines = 10; //How many lines to draw
for (i=draw_lines; i==0; i-=1) {
draw_text(x,y-string_height(“ABC”)*i,mplay_data_read(mplay_data_start-i);
}


Play around with the code, and make your own, cool interface, I hope you get a lot of use for it!

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