Most Frustrating Newbieness Ever
BlitzMax Forums/BlitzMax Beginners Area/Most Frustrating Newbieness Ever
| ||
I know I been a Blitz user for like eons and it's always the basic stuff that frustrates me. Actually I took a break after I couldnt get BMax to compile in Vista, but i'm back developing on my XP machine and thought i'd give it another go. Anyways, this is really daft and i've read samples and searched and meh, I just can't figure out the really simple easy stuff. Gimme quantum physics anyday! I'm trying to reference an objects data from within a method of itself, and dont know what the Blitz equivellent of the 'this.' operator is? Type server Field ip,port,pass$ Field timeOut,nextPacketSize Field socket:TSocket Field connect Field stream:TStream Function connection() this.timeOut=this.timeOut-delta If this.timeOut<0 this.nextPacketSize=0 this.timeOut=60000 If this.socket Then CloseSocket this.socket If this.stream Then CloseStream this.stream this.socket=CreateTCPSocket() this.stream=CreateSocketStream(this.socket) this.connect=ConnectSocket(this.socket,this.ip,this.port) If this.connect Then insim_ISI(this) EndIf End Function End Type Like I says, it's the simple stuff that always baffled me... /sigh Thanks for any help guys. |
| ||
You need a reference to an Object to use fields from inside a Function. Or, change those Fields to Globals - Unless you want more than one Server object live at a time (since globals are global to all objects, obviously ;-) ? Change Function to Method? Or, perhaps pass in your object... Function connection(this:server) ... Nice to see you haven't totally given up on BlitzMax :-p |
| ||
Aww cheers hun, you always where I diamond. Yup passing in this:server works a treat, just isn't the way i'm used to thinking, passing an object into itself. Sometimes I think I was only cut out to stack shelves. |
| ||
I think what you are trying to do is:Method connection() timeOut=timeOut-delta If timeOut<0 nextPacketSize=0 timeOut=60000 If socket Then CloseSocket socket If stream Then CloseStream stream socket=CreateTCPSocket() stream=CreateSocketStream(socket) connect=ConnectSocket(socket,ip,port) If connect Then insim_ISI(Self) EndIf End Method Inside methods you only need the Self-keyword (same as this) in special circumstances, like using the object itself as an argument. |
| ||
Yeah I just found the 'Self' operator myself and came back to post it, thanks :) |
| ||
Have you read this tutorial? http://www.blitzbasic.com/Community/posts.php?topic=59233 I found it very helpful in understanding how types work in BMax. |
| ||
Oh Blitz has a constructor too, handy - thanks :) |