I wrote the example like that because I thought it would be easier to understand(doh). Well, I don't know if it's exactly what you want, but I have changed the format of it so you might understand it better now:
`Constants --------------------------------
#constant MAXPLAYERS 10
#constant SENDGAP 100
`------------------------------------------
`Types ------------------------------------
type playerstates
keyup as boolean
keydown as boolean
endtype
`------------------------------------------
`Data -------------------------------------
global OURID as integer
global LASTSENT as integer
global MSGAMOUNTS as integer
global MSGAMOUNTR as integer
global YANGLE as float
dim playerdata(MAXPLAYERS) as playerstates
`------------------------------------------
`Ask for choice of mode
print "1. Host"
print "2. Join"
Input "Choice: ", choice
`If no choice then quit
if choice=0 then end
`If choice is 1 then host a multiplayer game
if choice=1
`Ask for username and IP to host on
input "Nickname: ", nick$
input "IP: ", ip$
`If either variable is empty, set a default
if nick$="" then nick$ = "Host"
if ip$="" then ip$ = "127.0.0.1"
`Host the multiplayer game
result = THost(ip$, MAXPLAYERS, nick$)
`If hosting failed then report to user and quit
if not result
print "Failed to host game"
wait key
end
endif
endif
`If choice is 1 then join
if choice=2
`Ask for username and IP to host on
input "Nickname: ", nick$
input "IP: ", ip$
`If either variable is empty, set a default
if nick$="" then nick$ = "Client"
if ip$="" then ip$ = "127.0.0.1"
`Join the multiplayer game
result = TJoin(ip$, nick$)
`If hosting failed then report to user and quit
if not result
print "Failed to join game"
wait key
end
endif
endif
`Retrieve our ID in the game and store it
OURID = TGetThisID()
`Set up sync
sync on
sync rate 60
`Make the player objects and hide ones not in use
for x=1 to MAXPLAYERS
make object cube x, 10
color object x, rgb(100+rnd(155), 100+rnd(155), 100+rnd(155))
position object x, 0, 5, 0
if not TPlayerExist(x) then hide object x
next x
`Make a matrix
make matrix 1, 1000, 1000, 10, 10
load image "sands.bmp", 1
prepare matrix texture 1, 1, 4, 4
do
`Output the framerate
text 0, 0, "Screen FPS: "+str$(screen fps())
`Show who is online
for x=1 to MAXPLAYERS
if TPlayerExist(x)
text 0, x*13, TGetPlayername(x)+"("+str$(x)+") is connected."
endif
next x
`Controls
if upkey() then move object OURID, 1
if downkey() then move object OURID, -1
if leftkey() then dec YANGLE
if rightkey() then inc YANGLE
yrotate object OURID, YANGLE
`Position and angle the camera
xPos# = cos(270-YANGLE) * 50 + object position x(OURID)
zPos# = sin(270-YANGLE) * 50 + object position z(OURID)
position camera xPos#, 30, zPos#
point camera object position x(OURID), 5, object position z(OURID)
`Check for new player. If so, show their object
newPlayer = TNewPlayer()
if newPlayer>0 then show object newPlayer
`Send our data to other players
if LASTSENT+SENDGAP<timer()
TPutFloat object position x(OURID)
TPutFloat object position z(OURID)
TPutFloat YANGLE
TPutByte upkey()
TPutByte downkey()
TSetMessageID 2
if rnd(10)<5 then TSendAll 1 else TSendAll
LASTSENT = timer()
inc MSGAMOUNTS
endif
`Receive data from other players
repeat
newMsg = TGetMessage()
if newMsg
inc MSGAMOUNTR
from = TGetSender()
write string 1, "From: "+str$(from)+" ID: "+str$(TGetMessageID())
x# = TGetFloat()
z# = TGetFloat()
yA# = TGetFloat()
playerdata(from).keyup = TGetByte()
playerdata(from).keydown = TGetByte()
XVAL = x#
ZVAL = z#
if object exist(from)
position object from, x#, 5, z#
yrotate object from, yA#
endif
endif
until not newMsg
`A little routine to smooth player movement
for x=1 to MAXPLAYERS
if OURID<>x and object exist(x)
if playerdata(x).keyup then move object x, 1
if playerdata(x).keydown then move object x, -1
endif
next x
`Let Tempest update itself
TSync
`Refresh the screen
Sync
loop