The only real code in the game is that of the obj_player. Here, I've commented it to what I think it's supposed to do:
//GAME START EVENT
dllinit(0,1,1) //Kick off 39DLL
if show_message_ext("Host or join?","Host","Join","")=2 //Let the player pick to host or join a match
{
hostip=get_string("Host IP","") //Get the ip of the desired host
global.otherplayer=tcpconnect(hostip,23033,1) //Connect to the desired host
if global.otherplayer=0 show_message("Unable to connect to server") //Bug check
x=500 obj_otherplayer.x=80 //Switch places so you are at the joining position
started=-1 //Remain idle
}
else
{
started=0 //Remain idle, but check for incoming connections
listen = tcplisten(23033, 2, 1); //Socket for monitering incoming connections
}//STEP EVENT
if started=0 //If checking for connections
{
sock = tcpaccept(listen, 1); //Accept connections
if(sock) //If there is an accepted connection
{
closesocket(listen); //Stop checking for new connections
global.otherplayer = sock; //Assign the new connection a variable
started=1 //Let the good times roll
}
}
if started=1 //If the good times are rolling
{
if mouse_check_button_pressed(mb_left) //Click
{
x=mouse_x //Move to
y=mouse_y //the mouse
clearbuffer(); //clean slate
writebyte(0); //Message type
writeshort(x); //x position
writeshort(y); //y position
sendmessage(global.otherplayer); //Send to other player
}
while(1) //repeat until broken
{
size = receivemessage(global.otherplayer); //recieve a message
if(size < 0)break; //if there was no message, stop
if(size == 0) //if the message was blank
{
show_message("Other player left the game"); //the player disconnected
game_restart(); //Try again
break;
}
mid = readbyte(); //What type of message was it?
switch(mid)
{
case 0: obj_otherplayer.x = readshort(); obj_otherplayer.y = readshort(); break; //Move the other player to the right spot
}
}
}So, I start up one copy of the game, and select host. It acts like it should, just staying idle waiting for an incoming connection, so I start up another copy of the game and select join. It asks for the IP, and I just put in my own (which has worked for all the examples/tutorials I've seen) and it waits (with that black screen) like it's trying to connect. It then shows the room like everything's good, but it won't let me click to move the player (host or client side).
It seems like the variable "started" is never changed to 1 (which now that I think of it, there's nothing to set it to 1 client-side... but it still ought to work on the host-side). It should be changed to 1 when the host receives the connection for the client, which it never seems to.
Anyone with any decent experience with 39DLL will probably find this pretty simple. I modeled this off of an example included with the DLL, so it's not exactly revolutionary.
If it'll help, you can get the exact file I have and try it out yourself: Download online.gmk
If you need any more information or whatever, just ask. I'd like to get into some multiplayer functionality, so this'll definitely help
Edited by Kajio, 06 July 2009 - 01:29 AM.












