Jump to content

Unigine Script: direct access to object, returned from function


photo

Recommended Posts

It could be great, if script allow next construction:

private:
Editor editor;
public:
Editor getEditor()
{
	return editor;
}

. . .

getEditor().showKeyLine();

 

It could be useful while using get/set methods

 

Now it can be do only like:

Editor editor = getEditor();
editor.showKeyLine();

Link to comment
  • 2 months later...

In Unigine manual says:

Accessing Elements of the Function

 

Source code (UnigineScript)

vec3 foo() { return vec3(1.0,2.0,3.0); }

printf("%f %f\n",foo().x,foo()[0]); // the result is: 1 1
printf("%f %f\n",translate(1.0,2.0,3.0).m23,translate(1.0,2.0,3.0)[14]); // the result is: 3 3

 

 

Why this feature not work with this:

PlayerActor foo() { return new PlayerActor(); }

log.message("test = " + foo().getName());

 

or with user's classes? What Am I doing wrong?

Link to comment

Why this feature not work with this:

PlayerActor foo() { return new PlayerActor(); }
log.message("test = " + foo().getName());

or with user's classes? What Am I doing wrong?

It is because the returned value is a class. This trick works only with simple types. As for classes, you need to cast them to their own type:

 

class Bar {
       string toString() {
           return "bar";
       }
   };

Bar bar() { return new Bar() };
printf("%s\n",Bar(bar()).toString());

Link to comment
×
×
  • Create New...