Jump to content

[SOLVED] extended Node class


photo

Recommended Posts

I'm making a custom class that extends Unigine's WorldTrigger. I find that two of the constructors below cannot "coexist". These would be the second and third constructors - TriggerObject(vec3 size), TriggerObject(string callback). The interpreter does not throw a correct error in the first place, which took me quite some time to figure out that the class can only work with one constructor but not the other.

 

#ifndef MY_OBJECT_H
#define MY_OBJECT_H
class TriggerObject : WorldTrigger {
public:

TriggerObject() : WorldTrigger(vec3_one * 2) {
 setEnterCallback("OnTriggerEnter", this);
 setLeaveCallback("OnTriggerExit", this);
}
TriggerObject (vec3 size) : WorldTrigger(size) {
}

TriggerObject(string callback) : WorldTrigger(vec3_one * 2) {
}
~TriggerObject () {
 delete extern;
}

void OnTriggerEnter (Node node, TriggerObject instance) {
 log.message(node.getName() + " entered.\n");
}

void OnTriggerExit (Node node, TriggerObject instance) {
 log.message(node.getName() + " exited.\n");
}
};
#endif

 

Has anybody else experienced this? What is wrong with my code?

Link to comment

Unigine script uses dynamic typing and essentially it is ignoring the pararmeters type in the constructors. It sees your code as having 2 construtors with only one parameter which for all intents and purposes recognises them both as;TriggerObject (int a)

It's the concept of being able to assign a value of one type to a variable of another. Ever noticed in any examples you have accessor methods that supposedly return int's for much more complicated data? Its the same concept. ^_^

Link to comment

Hello Mandee,

 

UnigineScript is not strongly typed, so there is no difference between

 

void method(string arg) { /* do something */ }

 

and

 

void method(int arg) { /* do something else */ }

Link to comment
  • 2 months later...

Add extra functionality to Node class :

 

class INode : Node
{
private:
Node add_editor(Node node)  {engine.editor.addNode(node);return node_remove(node);}
public:
int locked;
...
INode(string name)
{
   	locked = 0;
   	extern = node_load(name);
}
INode(string name, int addEditor)
{
   	locked = 0;
   	Node n = node_load(name);
   	extern = add_editor(n);
}
~INode()
{
}

Link to comment
×
×
  • Create New...