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 / [SOLVED] cant = getnetworkmessage(message) // to work =(

Author
Message
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 18th Jul 2018 01:28 Edited at: 18th Jul 2018 01:30
Hey guys. I have been building momentum and learning a lot about coding lately,until I hit this bump in the road. I am using Hughbus' magical PyxelLoader.agc to make a multiplayer wifi game. I can get host player to load the level, then I send a message using the following to tell clients which map to load.



the client needs to know which map to load, so I am using


Im getting an error that the message ID 0 does not exist. Before trying this I was using the bit from the AppGameKit example:


level always printed as 0. I cant really share the whole code on the forum because its a hefty bit, but maybe someone can enlighten me on my messaging error. As always, I appreciate any help or advice offered. You guys are the best! I tried researching this on my own but couldnt find much about sending and receiving simple messages aside from the AppGameKit example.
One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...

The author of this post has marked a post as an answer.

Go to answer

Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 18th Jul 2018 01:37
Another thing I just thought about, Im using the pc and an android phone to test the network. Do I need to use two computers or two devices?
One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 18th Jul 2018 04:54 Edited at: 18th Jul 2018 04:54
Dunno guys, this is the whole startup. Im still hitting a wall... message is always 0 on guest client's screen X_x

One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 18th Jul 2018 15:13 Edited at: 18th Jul 2018 15:15
After you check for GetNetworkMessage() you need to check it (in your case "message") isn't 0 before you try to read data from it, otherwise it will be trying to read a message that doesn't exist and thus you get the error.

if IsNetworkActive(NetworkID) <> 0
playerID = GetNetworkNextClient(NetworkID)
print(GetNetworkMyClientID(NetworkID))
if level# = 0
message = GetNetworkMessage(networkID)
if message > 0
level# = GetNetworkMessageFloat(message)
DeleteNetworkMessage(message)
endif
endif


Hope that makes sense (on phone ATM so sorry if it doesn't format correctly)
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 18th Jul 2018 19:38
So, it looks like the problem may be the connection, not the message. I added the following...



when the guest client connects it shows 2 players connected, but the host only says 1 player. Should the host only send the message once, or should it push that same message out continuously? Sorry for being so green guys, but this is my first time dabbling with network stuff.

i did add your code smallg, and it seems to make sense. Still not getting the message on the guest client though. I did just realize that I declared hosting = 1 in the very first if statement, which is a problem. fixed it but it wasnt a miracle cure.

One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 18th Jul 2018 22:36 Edited at: 18th Jul 2018 22:39
This post has been marked by the post author as the answer.
well I wiped everything and rewrote it from scratch. I did everything the same, and its sending the message now. This makes me realize I have no clue what Im doing, but its working... LoL



Thanks again, smallg for the help.
One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 19th Jul 2018 10:16
If both are connected you send the message once, if the other (client) is not connected then naturally it won't send to the client and the client will not receive the message when it connects after.
However the message will not be received instantly due to latency so you should loop checking for a message until it has received one using if messageid > 0 as posted earlier (I usually send a small string with any message just to identify what is in the message - I.e. "game" means it has the actual gameplay data etc and "setup" is from the map setup etc, so that if you receive a message you don't try to read incorrect data
With the correct handling of sending and receiving messages it shouldn't be necessary but definitely helps catch any stray messages that may have snuck through and as I find multiplayer can cause a lot of headaches its nice to limit as many potential problems as possible

Yes there should be 2 connections both ends
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu

Login to post a reply

Server time is: 2024-04-19 20:22:44
Your offset time is: 2024-04-19 20:22:44