Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
39dll problem
Topic Started: Nov 19 2010, 08:45 AM (650 Views)
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Ok the problem's I had are fixed but now new ones arrived :(

when 2 players plays a while the server give's an error array out of bounds in obj_client step event

but if it is only me playing and I play for a while and exit then the server doesn't pickup that I left so I dunno what the problem is i tried to think that globel.myid changes but I was wrong about that one it stays 0, but If I leave and enter again it becomes 1 and my previous character doesn't get destroyed
Posted Image


Offline Profile Quote Post Goto Top
 
Reikyrr
Forum God
[ *  *  *  *  *  * ]
Its about an array, what do you do with it?
~Inspirational quote~
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
server object create event
Code:
 

dllinit(0,true,true);
chat_initlines();
global.tcppoort=14804;
global.servertcp = tcplisten(global.tcppoort,10,1);
if (global.servertcp) then {
chat_addline("TCP socket opened on "+string(global.tcppoort)+".",c_green);
}
else
{
closesocket(global.servertcp);
chat_addline("could not start TCP connection via port "+string(global.tcppoort)+"!",c_red);
game_end();
exit;
}
global.maxplayers=10
for(i=0; i < global.maxplayers; i+=1)
{
global.players[i] = -1;
}


and step event
Code:
 

var clientsocket, player;
clientsocket = tcpaccept(global.servertcp,true);
if (clientsocket <=0) exit;
setsync(clientsocket,0);
receivemessage(clientsocket);
name = readstring();

if (instance_number(obj_client) = global.maxplayers)
{
clearbuffer();
writebyte(2);
sendmessage(clientsocket);
exit;
}

for(i=0; i < global.players; i+=1)
{
if (global.players[i]==-1) break;
}

clearbuffer();
writebyte(1);
writebyte(i);
sendmessage(clientsocket);
player = instance_create(0,0,obj_client);
player.pid = i;
player.tcp = clientsocket;
player.username = name;
global.players[i] = player;

clearbuffer();
writebyte(3);
writebyte(i);
writestring(name,true);
with(obj_client)
{
if (id!=player)
{
sendmessage(tcp);
}
}

with(obj_client)
{
if (id!=player)
{
clearbuffer();
writebyte(3);
writebyte(pid);
writestring(username,true);
sendmessage(clientsocket);
}
}
setsync(clientsocket,1);
chat_addline(name + " has joined the server.",c_yellow);


Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Im starting to give up on this, I tried now two ways to make a server
1 using the 39ster's example on his website
2 the one found here

on 1 the problem is
players sometimes randomly dissapears


on 2 the problem is
that array error and also when you play a few sec then you get disconnected or something
ill upload both of them


After I recreated the server and online stuff the 5th time it works now smoothly and so far no errors my brain is overpowerd now
Edited by DJ-Habana, Nov 20 2010, 08:29 AM.
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
ok guess it is not fixed
___________________________________________
ERROR in
action number 1
of Step Event
for object obj_39DllControl:

Error in code at line 26:
player = players[readbyte()]; //get id of player from playerlist
^
at position 17: Unknown variable players or array index out of bounds


and also

___________________________________________
ERROR in
action number 1
of Step Event
for object u_Character:

In script sendDirection:
Error in code at line 6:
sendmessage(obj_39DllControl.socket);
^
at position 31: Unknown variable socket


they ussually come when a player leaves
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Anyone willing to look at my game.
when there is 2 players everything works fine
but when a 3rd player joins and we play for a while then thats when things go wrong and the one disconnecting randomly get's one of those 2 errors
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
damn I hate 39dll

As soon AS one thing is fixed another arives
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
I am thinking of giving up...
Posted Image


Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
Your problems are actually not that difficult. I think you are making it harder than it is. Like this one:
Code:
 

sendmessage(obj_39DllControl.socket);

Try instead:
Code:
 

with(obj_39DllControl)
sendmessage(socket);

That might clear up the variable error. Remember that Game Maker is not always very reliable with the way it throws out errors.
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
I have deleted that server and game, created a new one so far it is running good, no errors well not tested with more than 2 players
I followed what you said there but Ill check if I can get someone to help me test.

just one question, in one example I saw they used
for(i=0; i < global.players; i+=1)
{
if (global.players==-1) break;
}

I am using it like
for(i=0; i < global.maxplayers; i+=1)
{
if (global.players==-1) break;
}




ok I tested, this is what happens now, play for about 2 min then the server starts to lag both game speeds are = 60
Edited by DJ-Habana, Nov 22 2010, 08:47 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
DJ-Habana
Nov 22 2010, 08:45 PM
I have deleted that server and game, created a new one so far it is running good, no errors well not tested with more than 2 players
I followed what you said there but Ill check if I can get someone to help me test.

just one question, in one example I saw they used
for(i=0; i < global.players; i+=1)
{
if (global.players==-1) break;
}

I am using it like
for(i=0; i < global.maxplayers; i+=1)
{
if (global.players==-1) break;
}




ok I tested, this is what happens now, play for about 2 min then the server starts to lag both game speeds are = 60
Then you are probably doing an endless loop on the server. Make sure you break the for-loop correctly so it doesn't fill the entire array with the same player id.
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Ok this is my code for the server:

var clientsocket, player;

numofp = instance_number(objPlayer);

clientsocket = tcpaccept(servertcp,1);
if (clientsocket <=0) exit;

setsync(clientsocket,0);//Set sync to false
receivemessage(clientsocket);
name = readstring();

//Go through the array to check for an empty space
for(k=0; k < global.maxplayers; k+=1)
{
if (global.players[k]==-1) break;
}

clearbuffer();
writebyte(myid);//Send the player who joined his player id
writebyte(k);
sendmessage(clientsocket);


player = instance_create(0,0,objPlayer);
player.pid = i;//Set Player's ID
player.tcp = clientsocket;//Set Socket where to send data
player.username = name;//Set players username
global.players[k] = player;//add player to the array


clearbuffer();
writebyte(joined);
writebyte(k);
writestring(name,true);//send all players that a new player joined
with(objPlayer)
{
if (id!=player)
{sendmessage(tcp);}
}

//send the player, the other players who joined
with(objPlayer)
{
if (id!=player)
{clearbuffer();
writebyte(joined);
writebyte(pid);
writestring(username,true);
sendmessage(clientsocket);}
}

//Set sync to true
setsync(clientsocket,1);

//Write on server the player name that joined
chat_addline(name + " has joined.",c_black);


There is still a bit lagg, but if I change the room speed of the server to 70 the lag is gone but I am not sure if that is effecient
Edited by DJ-Habana, Nov 22 2010, 09:28 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
after a while me and my friend played he got this error
ERROR in
action number 1
of Step Event
for object obj_39DllControl:

Error in code at line 64:
player = global.players[value];
^
at position 34: Unknown variable players or array index out of bounds
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Found my mistake lol

case playerleave:
value = readbyte();
>>>>> if value != global.Pid;{ <<<<< there is the mistake

player = global.players[value];
chat_addline(player.username + " has left the game.",c_black);
with(player)
{instance_destroy();}
global.players[value] = -1;}

FIXED code:
case playerleave:
value = readbyte();
if value != global.Pid{
player = global.players[value];
chat_addline(player.username + " has left the game.",c_black);
with(player)
{instance_destroy();}
global.players[value] = -1;}
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
OK somehow I get no errors but if 2 or more players play for like 5 min then the server crash with this error

___________________________________________
ERROR in
action number 1
of Step Event
for object obj_39DllControl:

Error in code at line 26:
player = players[readbyte()]; //get id of player from playerlist
^
at position 17: Unknown variable players or array index out of bounds



My game's roomspeed = 60 and the server is 70
if the server is also 60 there is a lag in the talking between them like I move and several seconds after that the player in the server moves
Edited by DJ-Habana, Nov 24 2010, 09:44 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
« Previous Topic · Off-topic · Next Topic »
Add Reply