Jump to content


Photo

39dll V2.5


  • Please log in to reply
2510 replies to this topic

#61 39ster

39ster

    GMC Member

  • GMC Member
  • 898 posts

Posted 12 July 2005 - 12:15 PM

Sorry i cant download that because brinkster wont let you download from offsite links. Anyways put this in the key up and key down event of the first paddle. Put it at the very top...before any other code in that event.
if(!global.master)exit;

Now do the same thing for paddle two but change it to:
if(global.master)exit;
  • 0

#62 matu666

matu666

    GMC Member

  • New Member
  • 74 posts

Posted 12 July 2005 - 12:20 PM

well i can download it fine ive tested it. yeah did that still the same it wont show the movment of the players on the other pc, but the ball does go off screen if the paddle isnt there.

Edited by matu666, 12 July 2005 - 12:25 PM.

  • 0

#63 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 12 July 2005 - 12:35 PM

I notice some errors in your script. Just as 39ster said, you must make sure that you're using 'if (!global.master)' to check who's the master and who's not. Since you haven't done this, they both move when one player presses a key.

And with player 2 you aren't even sending the data that he moved. :/
  • 0

#64 matu666

matu666

    GMC Member

  • New Member
  • 74 posts

Posted 12 July 2005 - 12:37 PM

well i followed the exapmle none of that was in it as i say im new to this, so what has to go in player 2
  • 0

#65 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 12 July 2005 - 12:42 PM

For example when you press the down key for player 2:

if (!global.master)
{
y+=4;
clearbuffer();
writebyte(0); // We call this message ID 0.
writeshort(x);
writeshort(y);
sendmessage(global.otherplayer);
}

Since there are only 2 players it doesn't really matter how much data you send. 5 bytes every packet. So 5 * 30 = 150 bytes per second. Download en upload means 300 bytes. That's about 0.3kb.
  • 0

#66 39ster

39ster

    GMC Member

  • GMC Member
  • 898 posts

Posted 12 July 2005 - 01:35 PM

well i followed the exapmle none of that was in it as i say im new to this, so what has to go in player 2

<{POST_SNAPBACK}>

The tutorial said nothing about it was for creating a pong game. I said i was using pong as an example.
  • 0

#67 matu666

matu666

    GMC Member

  • New Member
  • 74 posts

Posted 12 July 2005 - 02:52 PM

i know, and thanks but maybe you should create an example how to build a pong game for beginners like me.i will try to fix this but i am new to this sorry.
  • 0

#68 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 12 July 2005 - 03:44 PM

I'm writing a simple tutorial on how to do a simple movement system for two players. It will be done soon enough. Have some patience.

Edit: Alright, here it is, it isn't really that good, it's pretty simple, though.

Download here:

Winsockets DLL tutorial.

I won't be able to host it 24/7 though. The server will be offline some times.

Jochem.

Edited by Jochem, 12 July 2005 - 05:47 PM.

  • 0

#69 Jonit

Jonit

    GMC Member

  • New Member
  • 130 posts

Posted 12 July 2005 - 07:37 PM

hey 39ster, do you know how to make a monster?
Could you post here some kind of tutorial, please?

thanks.
^^
  • 0

#70 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 12 July 2005 - 07:43 PM

A monster? That's easy. There needs to be one controller-application, the server.

Make the server do stuff that the monster is supposed to do. Then send the monsters data to all players able to see it.

Monster data contains x and y. Some times even direction, speed and sprite_index.

Jochem.
  • 0

#71 Jonit

Jonit

    GMC Member

  • New Member
  • 130 posts

Posted 13 July 2005 - 02:29 PM

A monster? That's easy. There needs to be one controller-application, the server.

Make the server do stuff that the monster is supposed to do. Then send the monsters data to all players able to see it.

Monster data contains x and y. Some times even direction, speed and sprite_index.

Jochem.

<{POST_SNAPBACK}>


In some Future update, it will be added to 39ster's Zelda game?

Im just learning how to use this dll ^^

anyway, if someone want help me to make a monster.

wsaenotsock@hotmail.com

add me on msn ^^

:angry:
  • 0

#72 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 13 July 2005 - 10:56 PM

There are some GM-examples with monsters in it, even though they use Mplay. You can study them on how they're done. Doing this in this DLL works almost the same as doing it in GM.

Just let the server act like a monster should do. Like it isn't even multiplayer. Then every 5 steps, update his position, or something. (You'll get the idea.)

clearbuffer();
writebyte(0); // Message ID 0.
writeshort(x); // X position on the map.
writeshort(y); // Y position on the map.
sendmessage(global.player); // Send the message to the player.

This is really basic, you just have to tweak it a little, and add some stuff to it. If you still don't know how to do it, I suggest starting with something more simple first...

Jochem.

Edited by Jochem, 13 July 2005 - 10:57 PM.

  • 0

#73 39ster

39ster

    GMC Member

  • GMC Member
  • 898 posts

Posted 14 July 2005 - 11:59 PM

Ok thanks to Jochem for reporting a few bugs which should hopefully be fixed now. Before if you used writebyte() and entered a value over 127 the game would crash. Now you can use a value from 0 to 255 without it crashing. I have also cleaned up the readstring() functions because there was an error before which i cant really explain but hopefully its fixed now. Just re download the dll and you do NOT have to update the scripts :angry:.
  • 0

#74 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 16 July 2005 - 04:21 PM

I've got a (working) idea to utilize only one byte for direction, rather than two bytes. writebyte() can be a number from 0 - 255. And direction can be 0 - 360. You just have to divide the direction by 2 and make sure that you aren't sending 'broken' numbers, like 7,5; 210,5 etc.

For example, if you wanted to move in 8 directions, you have the direction right-up (North-east), which is the number 45. If you divide 45 by 2, it would be 22,5, which doesn't work with writebyte(). Make sure the number is 44. You don't notice any difference within the game.

This is very simple, but I think some people won't have thought of this.

Jochem.
  • 0

#75 Timmo

Timmo

    GMC Member

  • New Member
  • 558 posts
  • Version:GM:HTML5

Posted 17 July 2005 - 09:46 AM

Hi i am having a problem:
This is the code with what i want to send message to other player:
clearbuffer();
writebyte(10);
writestring(get_string("Write message to send to other player" ,""));
sendmessage(global.otherplayer);
And i am receiving it with this:
 mid = readbyte();           //Read the message id
  switch(mid)                 //Test the message id
  {
     case 10:
     tekst = readbyte(); break;
}
And in draw event i just draw text with a variable "text".
But when i send the tekst, then other player only gets numbers? How to fix it?
  • 0

#76 39ster

39ster

    GMC Member

  • GMC Member
  • 898 posts

Posted 17 July 2005 - 10:17 PM

Hi i am having a problem:
This is the code with what i want to send message to other player:

clearbuffer();
writebyte(10);
writestring(get_string("Write message to send to other player" ,""));
sendmessage(global.otherplayer);
And i am receiving it with this:
 mid = readbyte();           //Read the message id
  switch(mid)                 //Test the message id
  {
     case 10:
     tekst = readbyte(); break;
}
And in draw event i just draw text with a variable "text".
But when i send the tekst, then other player only gets numbers? How to fix it?

<{POST_SNAPBACK}>

Its because when your sending you have:
writebyte();
writestring();

but when you recieved the message you have
readbyte();
readbyte(); //why is this readbyte() when its a string?

Change your code to this:
clearbuffer();
writebyte(10);
writestring(get_string("Write message to send to other player" ,""), true); //i also added true in the second argument of writestring() which you should most of the time use.
sendmessage(global.otherplayer);
Recieving
 mid = readbyte();           //Read the message id
  switch(mid)                 //Test the message id
  {
     case 10:
       tekst = readstring(); 
     break;
}

I've got a (working) idea to utilize only one byte for direction, rather than two bytes. writebyte() can be a number from 0 - 255. And direction can be 0 - 360. You just have to divide the direction by 2 and make sure that you aren't sending 'broken' numbers, like 7,5; 210,5 etc.

For example, if you wanted to move in 8 directions, you have the direction right-up (North-east), which is the number 45. If you divide 45 by 2, it would be 22,5, which doesn't work with writebyte(). Make sure the number is 44. You don't notice any difference within the game.

This is very simple, but I think some people won't have thought of this.

Jochem.

Thats a good idea but you can get the number to be more exact to the original direction if you divide it by 1.41 instead of 2.
e.g
//send
writebyte(round(direction/1.41));
sendmessage(socket);

//recv
recievemessage(socket);
direction = round(readbyte()*1.41);

You can get 1.41 by doing 360/256

Edited by 39ster, 17 July 2005 - 10:45 PM.

  • 0

#77 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 18 July 2005 - 10:59 PM

I'm having a problem again.
When I try to synchronize the players in my game, all they do is 'jump'. I know why this is caused, I've searched for the bug. I'm pretty close to knowing what could have been caused this. Speed somehow messes up, and only a 0 is send. Results in not moving, and only updating the position of the other players some times, which results in 'jumping'.

Edit: Never mind, it was just a silly error of mine. I used receiveshort before the readbyte() while I should've used readbyte(). :/

Jochem.

Edited by Jochem, 18 July 2005 - 11:03 PM.

  • 0

#78 Gamingdl'er

Gamingdl'er

    GMC Member

  • New Member
  • 62 posts

Posted 19 July 2005 - 06:20 AM

This is truely awesome. I'm so impressed.

Infact, heres a quote of what I've said in the past

I'm so impressed, so impressed, that I have come back from VB6, and started using GM for all my applications. I love you 39ster(in a brotherly way).


  • 0

#79 Jochem

Jochem

    Pagoe Lord

  • New Member
  • 232 posts

Posted 19 July 2005 - 10:20 PM

Some things to check when your game is not working properly:

- Make sure that the write() functions are in the same order as the read() functions are.
- Make sure that you aren't trying to send a string via writebyte() or sending a real number via writestring().
- If your string doesn't have a fixed size, make sure that that argument1 in writestring() is set to true.
- Make sure that you aren't writing a number bigger than is allowed for a certain write() function, for example, don't send the number 301 via writebyte(). You may think that you have not done this, but some times this happens, even though you were really really sure it shouldn't have happened.

Well, that's all for now. I'll probably add more things later on.

Edit: I also made a simple script to pack & unpack multiple true/false variables (booleans) into a single byte. You can pack a maximum of 3 variables.

Download: Ultra pack scripts

Jochem.

Edited by Jochem, 22 July 2005 - 02:34 PM.

  • 0

#80 krstjern

krstjern

    GMC Member

  • New Member
  • 94 posts

Posted 30 July 2005 - 12:09 PM

Can someone tell me if this is rigth? Taleast around the recieving part, becouse i use peekmessage to get the message but still not delete it(Incase it's not the rigth ID) but if it is right, i want it to get the message(And delete it from the recv-buffer) and then just return the one i got from before, but wihout sending the byte that is the id.

//Wait for receiving a message
//Argument0=Socket to check
//Argument1=ID, -1 if anny message.
//Argument2=Timeout time(How long it should wait for a message) 1000=1 second(if you run i 30FPS)
//Return=The message received, or "" if no message found.
var timeout, mesid, temp;
clearbuffer();
timeout=current_time;
while(true)
{
mesid=peekmessage(argument0);
if(mesid>0) //Check if we got message
{
if(readbyte()==argument1 or argument1==-1)//Check if it is the ID we want
{
temp=readstring(mesid-1); //Return the message
recievemessage(); //Get the message(So it's not recieved again
clearbuffer();
return temp;
}
}
if(current_time>=timeout+argument2) //Check for timeout
{
return ""; //Timeout/No message found
exit;
}
}


EDIT: And a question: What does it mean to Terminate the string, in writestring(); ?

Edited by krstjern, 30 July 2005 - 12:13 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users