Type Callback functions
BlitzMax Forums/BlitzMax Programming/Type Callback functions
| ||
Oh man, i hoped to solve this all myself but i need help again. Ill keep it short. Local client:TClient = New TClient client.SetPlayerName("Patrick") client.Connect("127.0.0.1", 1234) client.OnConnect = blah Function blah() While Not KeyHit(KEY_ESCAPE) DrawText "Connected!", 10, 10 Delay(100) Flip Wend End Function Type TClient Extends TPacket Field name:String 'Callback Field OnConnect() Field OnConnectFail() Method SetPlayerName(name:String) Self.name = name 'if is connected, send new name End Method Method Connect(host:String, port:Int, timeout:Int = 30) Self.host = host Self.port = port Self.tcpsock = CreateTCPSocket() If ConnectSocket(Self.tcpsock, HostIp(Self.host), Self.port) 'Self.tcpstream = CreateSocketStream(tcpsock) If Self.OnConnect Self.OnConnect() Else If Self.OnConnectFail Self.OnConnectFail() End If End Method Why isnt this working? I get a "Unhandled excepton:: Call to uninitialized function pointer." error... If i call it. And if i check it for being set, it returns a false. It looks as if "client.OnConnect = blah" does have any effect at all. |
| ||
Because you're calling in the wrong order. client.OnConnect = blah client.Connect("127.0.0.1", 1234) Will work! |
| ||
LOL! Thanks >_> |
| ||
Oh man, it works now. This is hot. I love BlitzMax. I hope to finish my client module soon :) BlitzMax is so easy. Im amazed! |