Blockland Forums > Modification Help
Calling a function on an object
(1/1)
HellsHero:
I've always been confused about this, and I will try to explain best I can. When you call some function from an object and there's only one variable do you have to put it?
For example:

--- Code: ---function gameConnection::doStuff(%this)
--- End code ---

when I call it I would do this

--- Code: ---%this.doStuff();
--- End code ---

or this?

--- Code: ---%this.doStuff(%this);
--- End code ---

Is there much of a difference/prefered way to do it?
HellsHero:
Did a little searching and it seems like it would work either way? I'm still not completely sure, would it make a difference if the function had more than one variable? Would I include %this then? Or not include it?
otto-san:
dont include %this
HellsHero:

--- Quote from: otto-san on February 14, 2012, 09:50:53 PM ---dont include %this

--- End quote ---
Okay, thanks.
Port:
You only have to include the object itself if you're doing direct namespace calling.

This is valid: %obj.doStuff();
This is valid: gameConnection::doStuff( %obj );

The advantage of direct namespace calling is that you can do stuff like this:

--- Code: ---function myImage::onFire( %this, %obj, %slot, %x, %y )
{
wandImage::onFire( %this, %obj, %slot, %x, %y );
}

--- End code ---
Navigation
Message Index

Go to full version