Passing String to Method
BlitzMax Forums/BlitzMax Beginners Area/Passing String to Method
| ||
Why am I getting a 'Overriding method differs by type' error when I compile. It seems to have a problem with me using message as a string, but I'm not sure why... Thanks! foosh main.bmx Local message:String Network.serverConnect(127,5000) Print Network.updateChat() message=Input("> ") Network.sendMessage(message) network.bmx 'USAGE: sendMessage(message) Method sendMessage(message:String) WriteLine(stream,message) If message = "bye" Then Return ReadLine(stream) End End If End Method |
| ||
SendMessage() is a built-in Object method, with different parameters. |
| ||
Thanks a lot for your help. I now hit another wall, maybe you could help! main.bmx '-------------------------------------------------------------------GAME SETUP Import "network.bmx" '---------------------------------------------------------------LOOP VARIABLES Global o:GameNetwork '--------------------------------------------------------------------GAME LOOP While Not KeyDown(Key_ESCAPE) If Not o.serverConnect() Then Print "Error conencting to server..." End If Wend client.bmx Type GameNetwork 'USAGE: serverConnect() Method serverConnect() Global socket = CreateTCPSocket() If Not ConnectSocket(socket,HostIp(localhost),5000) Then Return False Global stream:TStream = CreateSocketStream(socket) If Not SocketConnected(socket) Then Return False Return True End Method End Type This just doesn't seem to start the connection with the server. It doesn't seem to do anything. I'm trying to structure my game properly, and so doing it correctly now will make all the difference for me later. Any help? Perhaps I'm not understanding how Types & Methods work fully? Thanks! foosh |
| ||
well, do you have a server that is running and awaits connection and binds socket etc? |
| ||
Yeah, the server is written in Python. It was working before I modified the structure of the game, so I'm very certain it has to do with the restructuring. foosh EDIT: I should point out that the server doesn't register that the client has connected either. |
| ||
Then I would guess it does never attempt to connect. In above code for example, I never see o = new GameNetwork and without it will never exist and run into a null error. |
| ||
Thank you, I was just syntactically wrong in initializing the GameNetwork. I changed Local o:GameNetwork to Local o:GameNetwork = New GameNetwork And now it works. Thanks for all your help! foosh |
| ||
I was just syntactically wrong in initializing the GameNetwork. Syntactically wrong? for later reference, you weren't initializing it at all. |
| ||
Syntactically wrong? for later reference, you weren't initializing it at all. I'm an experienced programmer-- I know how to use methods. BlitzMax has a different way of doing it from other languages. This is called not being familiar with the syntax, and therefore is a syntactical error. Thank you very much Brucey and dreamora for being patient and helpful! foosh |
| ||
Sorry, it was the way you said it. confused me. |
| ||
It always takes time to get used to a new language, that holds for all of us, so no problem :) happy it works now. |