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.

DarkBASIC Discussion / Going Multiplayer!

Author
Message
QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 3rd Feb 2003 01:58
Ok, here we go. I want to take my game online. I have created the game name and the type that I want using Create Net Game. I understand that command. now, I want to send variables. Apparently I should use
SEND NET MESSAGE INTEGER Player Number, Integer Value
and recieve them with
variable#=net message integer()
but I want to send 3 variables, x y and z.

If I send one with send net message integer and then send 2 more right after, how will the receive command get all three?? How can I make it so that I send out 3 variables, then recieve 3 from each player in the game.

Ok fill in the blanks:


Tywald
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 3rd Feb 2003 15:40
I would use a MEMBLOCK to store the variables like this:

`Make a memblock to send but delete the old one first.
IF MEMBLOCK EXISTS(1) = 1 THEN DELETE MEMBLOCK 1
`Make a memblock that that holds 12 bytes
MAKE MEMBLOCK 1,12
`Write the varibles into the memblock.
WRITE MEMBLOCK FLOAT 1,0,Player_X#()
WRITE MEMBLOCK FLOAT 1,4,Player_Y#()
WRITE MEMBLOCK FLOAT 1,8,Player_Z#()
`After that, send it to the players.
SEND NET MESSAGE MEMBLOCK 0,1

`Now the code to recive the memblock and store its contests.
REPEAT
GET NET MESSAGE
IF NET MESSAGE TYPE() = 4
`Who sent the memblock?
Player = NET MESSAGE PLAYER FROM() `<-- I think that´s the command.
`Now create an another memblock from the memblock i got.
NET MESSAGE MEMBLOCK 2
Player_X#(Player) = MEMBLOCK FLOAT(2,0)
Player_Y#(Player) = MEMBLOCK FLOAT(2,4)
Player_Z#(Player) = MEMBLOCK FLOAT(2,8)
ENDIF
UNTIL NET MESSAGE EXISTS() = 0

`That´s it, now you can update the players stats whit the variables you got from their memblocks.

An another way to solve this problem is to create a long string that contains the variables you want to send.
For example:

Packet$=STR$(Player_X#())+"#"+STR$(Player_Y#())+"#"+STR$(Player_Z#())
SEND NET MESSAGE STRING 0,Packet$

When you get a "Packet$" you can get the variables whit the LEFT$,RIGHT$ and MID$ commands.

But right now you should stick to the MEMBLOCK since it seems that Dark BASIC PRO like to store the real nummbers in a incorrect way.

-Tywald
Hubdule
22
Years of Service
User Offline
Joined: 3rd Sep 2002
Location: Gundelsheim
Posted: 3rd Feb 2003 16:03
The problem here is:

If you try sending a packet for each position change you'll soon find the problem of "overloading" the connection ! To prevent this send the position only once/twice or more often per sec. and interpolate all frames between the last and the current position. Otherwise you can forget about multiplayer. It won't work right ... See also:

DBPro (demo/full) V.3.1 -> Help -> Help Content -> Technical documents -> Multiplayer Secrets

QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 3rd Feb 2003 21:49
thanks you tywald, that was very helpful. A few questions:
WRITE MEMBLOCK FLOAT 1,0,Player_X#()
WRITE MEMBLOCK FLOAT 1,4,Player_Y#()
WRITE MEMBLOCK FLOAT 1,8,Player_Z#()

Why 0,4 and 8? Are they positions in the memblock? I thought there was no position 0. Could it just as easily be 1, 2 and 3?

IF NET MESSAGE TYPE() = 4...endif
is type 4 a memblock? If i am only sending memblocks ,do I really need this? What is the number for an intiger, or a float?

Player_X#(Player) = MEMBLOCK FLOAT(2,0)
so Player_X#(Player) is an array? Wouldn't "Player" return the string of the player's name...? to extract from it would I need to do something like:
For x=1 to totalplayers#
position object x,Player_X#(x),Player_Y#(x),Player_Z#(x)
next x

Would that work? in its current state?

NET MESSAGE MEMBLOCK 2
Is that proper syntax? I'm guessing it takes the message recieved and turns it into memblock 2, but the syntax doesnt look like it would work.

And finally, would this code work compiled? (I'm at school)
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Feb 2003 00:40
The magic numbers are offsets within the memory block, not positions (read as write to the start of the memblock PLUS the offset). And each float is 4 bytes in size...

Yes, type 4 indicates a memblock.

The code as it stands only deals with 1 player position ... I guess he thought you'd be better off working it out



Reverse the login to get the position out of a memblock ... heh, I guess I think you could do with the practice too


Yes, NET MESSAGE MEMBLOCK 2 is the right syntax, and will clear and then create the memblock if it already exists.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Feb 2003 00:40
Login? I meant logic
QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 4th Feb 2003 05:47
ok...now what code would I need so that if I executed the code, then left it running and executed a second code, the two games could connect?

I have something like this



But that doesnt seem to work if I run 2 programs at the same time. Any help, please!?
Tywald
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 4th Feb 2003 10:00
Quoth:
"so Player_X#(Player) is an array? Wouldn't "Player" return the string of the player's name...? to extract from it would I need to do something like:"

Whit the NET MESSAGE PLAYER FROM() command you´ll get a number that is stored whitin "player".

Yes, your code should work but remember that all players need to declare the arrays for else only the hosts players will move.

-Tywald
QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 4th Feb 2003 14:32
but if I use that code, the two games do not recognize each other
Tywald
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 4th Feb 2003 16:12
Quoth:

I think we are not speaking about the same code, i was speaking of the code where you have after getting each variable from the players and stored it you simply reposition the objects using those variables. Well as i said that should work.

For the network code you´re asking about:
When you want to join a game you´ll need to check for available net games using the PERFORM CHECKLIST FOR NET SESSIONS before you try to join a game.

-Tywald
QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 5th Feb 2003 01:28
MY TWO GAMES CAN RECOGNIZE EACH OTHER!!!!! SWEET RANCID DONEY LOVE FOR ALL!!!! Thanks a lot Tywald, IanM and...Tywald....you 2 really helped me out. Guess who's gonna be in the creediiits!
Tywald
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 5th Feb 2003 10:31
Glad that i could help you Quoth.

- Tywald
QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 5th Feb 2003 14:29
donkey* not doney
I was excited
Mr_Insane
22
Years of Service
User Offline
Joined: 14th Nov 2002
Location: United States
Posted: 6th Feb 2003 20:23
Is there a multiplayer code for those who dont have the enhanced DBv1?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Feb 2003 20:36
You can get an add-on for multiplayer here: http://tmedia.hypermart.net/

I've never used it, but it may be worth trying.

Login to post a reply

Server time is: 2025-05-10 00:28:26
Your offset time is: 2025-05-10 00:28:26