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 / Problem with Network local variables

Author
Message
lelu111
1
Years of Service
User Offline
Joined: 2nd Mar 2023
Location:
Posted: 17th Jul 2023 10:37
Hey!
I want to make my game a multiplayer mode. I tried making messages between devices but it didn't work well and it even seemed easier to code using network network local integers. So I tried it but it doesn't work for some reason.
In my example program seem to be working fine, it connects (every device says it's connected) but they don't get the variables, and it always prints 0. I attached the code I'm usig. I already asked it on Discord but did not get the answer to get it to work.

Attachments

Login to view attachments
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 4th Aug 2023 02:27
so your network name is "network name on your local network and your computers name is hostname?"

lelu111
1
Years of Service
User Offline
Joined: 2nd Mar 2023
Location:
Posted: 12th Aug 2023 14:03
Yes, it was a placeholder for testing. If you think it is the root of the problem then I will try to change it, but I assumed that it would not cause any error if i use temporary values for testing.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Nov 2023 00:28 Edited at: 18th Nov 2023 00:29
The problem is your code structure is completely fubar. Let's start with the host portion. After it creates the network and listens for clients, it'll go on to an infinite do-loop. There is no condition where it will ever exit that loop and therefore you won't be able to press the other virtual button. It's the same story for "join" portion of your code. And you've used NetID for the serve and client. Use separate variables.

I've never used the networking commands before, and frankly it confuses me. The way the help files make it sound like, you have to grab all clients before you can do anything after creating the network. Which to me is strange behavior as how can any clients connect before the network has been established?

From what I've read in the help docs about these commands and looking at your code, I'd say the client never gets the variable from the server because you're setting "var" before any clients have connected. So unless the server has persistent data and pushes old values to new clients (highly doubt it) then "var" simply doesn't exist when you try to read it. I don't really like how GetNetworkClientInteger() returns 0 if there's nothing to read. What if I wanted to send a value of 0 to clients?


This is untested and I barely have an understanding of the multiplayer commands, but I *think* this would work.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Scribble
7
Years of Service
User Offline
Joined: 2nd Apr 2017
Location:
Posted: 10th Jan 2024 12:16 Edited at: 10th Jan 2024 12:19
I have tried 'local' network variables before, but the thing simply doesn't work, the problem is as you have described. No value is returned whatsoever. I gave up on it. Maybe somebody else managed to get it working, idk.
So instead, I've been using the 'normal' TCP/IP networking commands ever since. It's very reliable as far as I have have tested it. It has been under development since early version of AppGameKit with bugfixes done, so it is really reliable.
I highly suggest using the TCP/IP networking commands rather than local network commands. By using TCP/IP, you can convert your game from local multiplayer to online multiplayer very easily later on too.
This default example project is all you need:

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-05-01 13:38:58
Your offset time is: 2024-05-01 13:38:58