<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...