Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / BatVinks multiplayer code

Author
Message
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 18th Feb 2016 20:41
https://www.thegamecreators.com/pages/newsletters/newsletter_issue_147.html#5

So, this is great, but sending strings is quite useless. So if I convert this to send floats, how the receiving end is going to get them? Allow me to give example:


If host sends x#=153.5, is the client going to see x#=153.5 or just the 153.5 ?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Feb 2016 09:22
You can make up the message from any number of parameters of any type. You can send a package of many pieces of data, of all types. Just make sure for every add, you do a get, e.g

AddNetworkMessageFloat(msgId, 123.45)
AddNetworkMessageString(msgId, "Hello World")
..
x# = GetNetworkMessageFloat(msgId)
text$ = GetNetworkMessageString(msgId)


Each one is received into a variable of the correct type.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 19th Feb 2016 16:07
Yeah, so it would be best to send like this:

Example, player coordinates X,Y

send string "players X"
send float x#
send string "players Y"
send float y#

so the receiving end can get those in the right order?

Like sending bunch of floats, the client has to receive them at the same order as host sends them?



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Feb 2016 17:12 Edited at: 19th Feb 2016 17:13
Yes that's right.

I organise it by always starting by sending a 3 character string. This tells me what I am going to receive. For example:

"MOV" - character movement. Receive a character ID (Integer) followed by 3 floats (X,Y,Z)

AddNetworkMessageString(msgId, "MOV")
AddNetworkMessageInteger(msgId, myCharacter.id)
AddNetworkMessageFloat(msgId, myCharacter.x)
AddNetworkMessageFloat(msgId, myCharacter.y)
AddNetworkMessageFloat(msgId, myCharacter.z)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 19th Feb 2016 19:24
Gotcha. Thanks.

Login to post a reply

Server time is: 2024-04-19 01:37:23
Your offset time is: 2024-04-19 01:37:23