How to use ControllerInteractable in child entity script


#1

Not the first time that this is biting like a pitbull.
It’s just pretty complex, wel javascript where never my favorite language.

But how do i get the handcontroller working in entity script that is set as child ?
I copied working code to the child. changed a few small things. And it generate soem error

`[UncaughtException] ReferenceError: Can’t find variable: ControllerInteractable in Entities

I cleaned the code a bit before post it here.

(function()
{
	var Ent;	
	var parentID;
	
	this.preload=function(entityID)
	{ 
		Ent = entityID;
        parentID = Entities.getEntityProperties(Ent, ['parentID']).parentID;
		print("Parent EntID  "+parentID);		
	}	

    function sendmessage()
	{		
            print("message send");
		Entities.callEntityMethod(parentID, 'DOORhandleTouched');
    };
	

    clickDownOnEntity = function(entityID, mouseEvent)
	{ 
		sendmessage();
    }	
	
	ControllerInteractable.prototype.startNearTrigger = function() 
	{
		sendmessage();
	}	
	
	return new ControllerInteractable();		

})`

What am doing wrong this time ? the wiki does not find ControllerInteractable.

ADD: Looking more on the wiki. but so far i get the idea that there’s not much or any documentation about the trigger and grab functionality.

I just did add, because i forgot that again. and i wish that that font where bigger. so tiny !

{
  "grabbableKey": {
    "grabbable": true,
    "wantsTrigger": true
  }
}

But still no luck. so need to search more on the wiki.
Well there’s Hand Controller API but no examples there.

For now, back to the good old desktop only mode. because that works.
HMD make things complex. Add the hand controller stuff later back in until soemone told me how. There’s really no info on the wiki with examples. at least not in the javascript api section as far i see.

This example, for mouse only works.

(function()
{
	var Ent;	
	var parentID;
	
	this.preload=function(entityID)
	{ 
		Ent = entityID;
            parentID = Entities.getEntityProperties(Ent, ['parentID']).parentID;
		print("Parent EntID  "+parentID);		
	}	

    function sendmessage()
	{		
            print("message send");
		Entities.callEntityMethod(parentID, 'DOORhandleTouched');
    };
	

    this.clickDownOnEntity = function(entityID, mouseEvent)
	{ 
		sendmessage();
    }		

})

#2

You haven’t defined the ControllerInteractable and alot of your stuff simply isnt bound to anything.

(function()
{
  var Ent;	
  var parentID;

  // The following line will never be called. because its not bound to anything returned.
  this.preload=function(entityID)
  { 
    Ent = entityID;
    parentID = Entities.getEntityProperties(Ent, ['parentID']).parentID;
    print("Parent EntID  "+parentID);		
  }

  function sendmessage()
  {
    print("message send");
    Entities.callEntityMethod(parentID, 'DOORhandleTouched');
  };

  // The following line will never be called. because its not bound to anything returned.
  clickDownOnEntity = function(entityID, mouseEvent) instead
  { 
    sendmessage();
  }	

  var ControllerInteractable = function () {}; // This defines the ControllerInteractable object
  // ControllerInteractable does the exist without the above
  ControllerInteractable.prototype.startNearTrigger = function() 
  {
    sendmessage();
  }
  return new ControllerInteractable();
})

You have to remember,

  • Entity script is run as a callback that returns a JS Object which the client interfaces with.
  • Client Scripts are run as is, line by line…

To make -everything work- you have to make sure to bind startNearTrigger AND clickDownOnEntity callbacks into a single object that is returned.

Ideally, continueing from earlier.

(function()
{
  function sendmessage()
  {
    print("message send");
    Entities.callEntityMethod(parentID, 'DOORhandleTouched');
  };

  var ControllerInteractable = function () {}; // This defines the ControllerInteractable object
  // ControllerInteractable does the exist without the above
  ControllerInteractable.prototype = {
    Ent: null,
    parentID: null,
    preload: function(entityID)
    { 
      this.Ent = entityID;
      this.parentID = Entities.getEntityProperties(this.Ent, ['parentID']).parentID;
      print("Parent EntID " + this.parentID );		
    },
    startNearTrigger: function() 
    {
      sendmessage();
    },
    clickDownOnEntity: function(entityID, mouseEvent)
    { 
      sendmessage();
    }	
  }
  return new ControllerInteractable();
})

I suggest reading up on more on JS Objects to avoid issues such as these.


#3

This problem i did figure already out after i found my older test example.
It;s more difficult to put everything in one script. tempted to reverse that idea and go back to 2 scripts. more fool proof.


#4

Its absolutely do able with a single script. You just have to wrap your head around it and think in the way.


#5

Well, like i wrote in the other topic. It worked with one script. But it start to trigger the child click evenbt double after a reload. and every time i reload the script one got add. I just tried to remove that event with scriptending. (mabye wrong one) but that break things only more. Bugs or User errors i dont know.

So i moved the latest scripts to backup dir, and go later with the odl double script one. I think there to many bugs and there’s not enough documentation, Also 15 years ago my head would possible wrap more easy around this then now.

In time, weeks, months or years i will figure out newer and better ways.
Not going to run rounds and rounds to only safe one script. It’s more important that you move forward and see soemthing happens and get done.