TNet - Getting Flushmem error
BlitzMax Forums/BlitzMax Programming/TNet - Getting Flushmem error
| ||
Global NetPlayer:Int[1000] Global LocalPlayer:Int Function HOSTGAME:Int(port:Int) TNet_HostUDP port LocalPlayer = TPlayer.CREATEPLAYER(100,100) End Function Function JOINGAME:Int(ip:String,port:Int) TNet_JoinUDP ip,port LocalPlayer = TPlayer.CREATEPLAYER(Rand(320),Rand(240)) For Local nn = 0 To TOTAL_PLAYERIDS NetPlayer[TNet.ID] = TPlayer.CREATEPLAYER(100,100,True,TNet.ID) Next End Function Function CONNECTEDGAME:Int() If TNet_NewClient() NetPlayer[TNet.ID] = TPlayer.CREATEPLAYER(100,100,True,TNet.ID) End If End Function Function SENDDATA() For Player:TPlayer = EachIn PlayerList If Player.NetP = False TNet_SendUDP(2,Player.NX) ElseIf Player.NetP = True If TNet_Receive(2) Player.PX = Int(TNet.Data) End If End If Next End Function Im having Problems sending info to the player.. I want to use strings only btw, so please if anyone has a suggestions let me know what im doing wrong Player is the Type used in my PLayer Type code.. |
| ||
The code looks fine. You get flushmem error? Or does it crash with flushmem? You say you want to use strings only? Instead of: TNet_SendUDP( 2, Player.NX ) Go: TNet_SendUDP( 2, ZInt(Player.NX) ) Instead of: If TNet_Receive( 2 ) Player.PX = Int( TNetData ) Go: If TNet_Receive( 2 ) Player.PX = XInt( TNetData ) Please explain more. |
| ||
I changed my code up a bit, but it still crashes at the Flushmem like your not clearing your types right in TNet, Im sure it has to do with the SendUDP command and Receive, but im not sure, were because it send the info for a bit then flushmem crashes like it gets over loaded... Also you don't explain how to use ZInts(blah) very well I would use that command to send more than one thing thru client at once, but I don't understand this command new code Global NetPlayer:Int[1000] Global LocalPlayer:Int Function HOSTGAME:Int(port:Int) TNet_HostUDP port LocalPlayer = TPlayer.CREATEPLAYER(100,100) End Function Function JOINGAME:Int(ip:String,port:Int) TNet_JoinUDP ip,port LocalPlayer = TPlayer.CREATEPLAYER(Rand(320),Rand(240)) For Local nn = 0 To TOTAL_PLAYERIDS NetPlayer[nn] = TPlayer.CREATEPLAYER(100,100,True,TNet.ID) Next End Function Function CONNECTEDGAME:Int() If TNet_NewClient() NetPlayer[TNet.ID] = TPlayer.CREATEPLAYER(100,100,True,TNet.ID) End If End Function Function SENDNETINFO() For Player:TPlayer = EachIn PlayerList IF Player.NetP = False Player.NX = Player.PX Player.NY = Player.PY Player.NDirection = Player.Direction Player.NAction = Player.Action TNet_SendUDP(2,Player.NX+","+Player.NY+","+Player.NDirection+","+Player.NAction) End If Next End Function Function READNETINFO() local data1,data2,data3 If TNet_Receive(2) 'If Player.IDNumber = TNet.ID data1 = Instr(TNet.Data,Left(TNet.Data,1)) Print data1 data2 = Instr(TNet.Data,",",data1) Print data2 data3 = Float(Mid(TNet.Data,data1,data2)) Print data3 For Player:TPlayer = EachIn PlayerList If Player.NetP = True and Player.IDNumber = TNet.ID Player.PX = data3 End If Next End If End Function |
| ||
Const NEW_PLAYER = 1 Const INFO_PLAYER = 2 Function HOSTGAME:Int(port:Int) TNet_HostUDP port LocalPlayer = TPlayer.CREATEPLAYER(100,100,False,TNetMy.Net_ID) End Function Function JOINGAME:Int(ip:String,port:Int) TNet_JoinUDP ip,port LocalPlayer = TPlayer.CREATEPLAYER(100,100,False,TNetMy.Net_ID) End Function Function CHECKPLAYER() local data1,data2,data3 If TNet_NewClient() NetPlayer[TNetID]=TPlayer.CREATEPLAYER(100,100,True,TNetID) TNet_SendUDP(NEW_PLAYER,"Welcome",TNetID) End If If TNet_Receive(NEW_PLAYER) NetPlayer[TNetID]=TPlayer.CREATEPLAYER(100,100,True,TNetID) End If If TNet_Receive(INFO_PLAYER) For PLayer:TPlayer = EachIn PlayerList If Player.IDNumber = TNetID data1 = Instr(TNetData,Left(TNetData,1)) DrawText data1,8,8 data2 = Instr(TNetData,"|",data1) DrawText data2,8,24 'Player.PX = Float(Mid(TNetData,data1,data2)) 'Player.PY = Float(Mid()) End If Next Else DrawText "No Data",8,8 End If End Function Function SENDPLAYER() local datasend:string For PLayer:TPlayer = EachIn PlayerList datasend = Player.NX+"|"+PLayer.NY If Player.IDNumber = TNetMy.Net_ID TNet_SendUDP(INFO_PLAYER,datasend) End If Next End Function This is the latest attemp, this system just crashes the host window |
| ||
Concerning the "flushmem error" I'll look into it. It does happen to me too, but I doubt it's my fault. I'll still take a look at it and see if I can figure it out. Also you don't explain how to use ZInts(blah) very wel Have you checked the command referense at www.truplo.com/TNet? I hope it is explains well, or I will change it for the better, I like feedback =) I am going to write a tutorial on packing (a detailed one) but I haven't had time for it. It'll come.. in time.. Anyhow the point with my packing commands is to make your life simpler. So it would be pointless to use your own packing on top of it =) Instead of: ( SEND ) datasend = Player.NX+"|"+PLayer.NY .. TNet_SendUDP(INFO_PLAYER,datasend) Go: datasend = ZInt(Player.NX)+ZInt(Player.NY)'Dynamic packing .. TNetSendUDP( INFO_PLAYER,datasend ) Instead of: ( RECEIVE ) data1 = Instr(TNetData,Left(TNetData,1)) DrawText data1,8,8 data2 = Instr(TNetData,"|",data1) DrawText data2,8,24 Player.PX = Float(Mid(TNetData,data1,data2)) Player.PY = Float(Mid()) Go: Player.PX = XInt( TNetData ) Player.PY = XInt( TNetData ) Magic eh? If you need floats use ZFloat() and XFloat(), If you need to pack several Strings use ZString() and XString(). The logic: Z is for Zip I.E. Pack. X is for eXtract I.E. UnPack. You can also use a similar command called ZInts, note the extra "s". It works like this: DataToSend$ = XInts([ X, Y , Dir , Speed , Acceleration, LastX, LastY, ID, Trigger1, Color]) All these numbers will be packed into the string, DataToSend$ Send this string in a message. Unpack it like this: If TNet_Receive(2) NewData$ = TNetData$ Debuglog "Start Size of NewData: "+NewData.Length X = ZInt( NewData$ ) 'First int Y = ZInt( NewData$ ) 'Second Int Dir = ZInt( NewData$ ) 'Third Int Speed = ZInt( NewData$ ) 'You get he point Acceleration = ZInt( NewData$ ) 'Fifth Int LastX = ZInt( NewData$ )' And so on.. LastY = ZInt( NewData$ ) ID = ZInt( NewData$ ) Trigger1 = ZInt( NewData$ ) Color = ZInt( NewData$ )'Last Int Debuglog "End Size of NewData: "+NewData.Length 'If you packed 10 Ints like I did in this example then NewData$ will be 0 in size! |