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.

AppGameKit Classic Chat / Please help me with a multiplayer question

Author
Message
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 20th Apr 2013 02:03
I'm trying to make a two/four player LAN game. I just want it to be where 2 or 4 players login and move around.

Here is the server code:




Here is the client code:


Thank you for your time.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th Apr 2013 18:04
Well, you haven't asked a question or said that you are having a problem. What do you want from us?

First of all, do your sync() at the end of the main do loop, not at the beginning.

I would say that your network code probably won't do what you expect. It assumes that there is a message every frame from two players and that they always appear in the same sequence.

You cannot assume that the timing on the remote players is going to be the same between them and between the network.

And there is nothing in your code on for either network or remote that passes information back to the remote app.

You specify 4 players in the variable NumPlayer and then never use it.

The hosting app doesn't need to create sprites for the players, only the player apps need sprites to show what is going on and to do things.

The player app should send messages about its own movements with an id unique to it and receive messages from the hosting app about the movements of other players.

Each player should have a unique id associated with a sprite for its movement. Somehow, when a new player connects, it should be checked to see if there are still open spaces and the hosting app should send back a number to identify which sprite it uses or zero (probably) to indicate the game is full.

There are a bunch of different messages to go between the player apps and the hosting app for 'logging in', 'making a move' and 'logging out' for example.

The code for checking to see if connections still exist needs to be done more than once (probably once a sync cycle) so that players can be removed quickly.

All of the above is just some of the stuff you need to think about and basically a stream of consciousness 'inspired' by your code example.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 23rd Apr 2013 05:13
Thank you for your reply, I know this is going to be hard and take a lot of work. I want to have a server host 4 players, then you log onto it with your phone or tablet. I'm not sure how you go about having a server wait for players than listen to each player.

Thanks
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Apr 2013 09:38
its easier for you beginning without messages and
use this and similar:
SetNetworkLocalInteger
float GetNetworkClientFloat( iNetID, client, name )
SetNetworkClientUserData( iNetID, client, index, value )
it have a automatic transfer.

your server do remote all clients and collect the input of them.
if you use messages you must send a command name with it because
you don't know what it is.
AddNetworkMessageString( iMsgID, "JoyInput")
DMJ
13
Years of Service
User Offline
Joined: 6th Sep 2011
Location: Australia
Posted: 25th Apr 2013 02:44
Thank you for your reply Markus.

I'm using my phone as a controller, for my computer. All, I want is to have at least 4 players interact with each other.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Apr 2013 10:18
4 phones > 1 computer?

types are useful for holding data
type TPlayer
spr as integer
health as float
clientid as integer
joyx as float
joyy as float
joyb as integer
...
endtype
global dim Player[4] as TPlayer
...
for i=1 to 4
GetPlayerInput(i)
PlayerMove(i)
next

Login to post a reply

Server time is: 2024-11-24 12:05:05
Your offset time is: 2024-11-24 12:05:05