Page 1 of 1

Static Functions

Posted: Friday 12th July 2019 11:10am
by ShaneP
Are we able to do this in gambas

if we have a class called Vector with a function "subtract" can we then do

Vector mouse = new Vector(mouseX,mouseY);
Vector dir = Vector.subtract(mouse,location);

Re: Static Functions

Posted: Friday 12th July 2019 1:49pm
by cogier
Hi ShaneP and welcome to the forum.

Can you explain exactly what you want to achive. I'm not sure I understand the question that well.

Re: Static Functions

Posted: Friday 12th July 2019 7:07pm
by Cedron
Your example is chock full of reserved (or previously used) words, so I'm not going to manipulate it into proper syntax.

The answer is "Yes, you can"

Static subs can only reference static variables. Static variables are shared across all instances. A static sub can create an instance of the class and return it. A static sub can also take an instance as an argument. Of course, the same is true for non-static (instance methods) too.

It shouldn't be too difficult for you to whip up an example project to demonstrate this. If you encounter any trouble, just ask for help.

Ced