function SetUpNetwork()
rem *** Create Host and Client buttons ***
AddVirtualButton(1,10,20,20)
SetVirtualButtonText(1, "Host" )
AddVirtualButton(2,30,20,20)
SetVirtualButtonText(2, "Join" )
rem *** Wait till button pressed ***
repeat
HandleButtons()
Sync()
until joined = 1
rem *** Wait until both machines connected or timed out (30 seconds)***
time = GetSeconds()
repeat
print(GetSeconds())
until GetNetworkNumClients(netid)=2 or GetSeconds()-time>30
rem *** If we don¡¦t have 2 clients, close game ***
if GetNetworkNumClients(netid)<>2
CloseGame()
endif
rem *** Get client¡¦s id ***
clientid = GetNetworkMyClientID(netid)
Print("Name: " + GetNetworkClientName(netid, clientid))
rem *** Delete the network buttons ***
DeleteVirtualButton(1)
DeleteVirtualButton(2)
endfunction
function HandleButtons()
rem *** If Host button pressed and not already joined ***
if GetVirtualButtonPressed(1)= 1 and joined = 0
rem *** Host the app ***
//print ("hosting")
netid = HostNetwork("TicTakToe","Hostmachine",1026)
//print("netid =")
//print (netid)
rem *** Record as joined ***
joined = 1
endif
rem *** If Client button pressed and not already joined ***
if GetVirtualButtonPressed(2)=1 and joined = 0
rem *** Join as client ***
clientname$ = Str(GetSeconds())
//print ("joining")
netid = JoinNetwork("TicTacToe",clientname$)
rem *** Record as joined ***
joined = 1
endif
endfunction
this is the code i copied out of the hands on book