How can I call a test method from self hosted?

I download my project and I have a method which I can call it like:'colliders:test', 'Whatever string');

What the method does:

Colliders.prototype.test = function(text)


    <script src="__modules__.js"></script>
    <script src="__start__.js"></script>
    <script src="__loading__.js"></script>
        var app = pc.Application.getApplication();'colliders:test', "Entro");
        app.on("start", function () {
        // get the root of the scene.
        var hierarchy = app.root.getChildren()[0];


But at the moment that I run the project, It doesn’t work. I hope you can help me.

Hi @Axel_Saucedo, you are almost there.

In your Colliders script you need to attach an event listener that is calling as a response the test() method:

Colliders.prototype.initialize = function(){'colliders:test', this.test, this);

Now in your index.html, you need to wait for the pc.Application initialize method before firing any script events. That is called after all script initialize methods have finished executing (so your event handler has been attached):

        var app = pc.Application.getApplication();
        app.on('initialize', function(){
  'colliders:test', "Entro");
1 Like

Thanks!! It worked!!

1 Like

Sorry to bother you. Do you know if you can create a playcanvas method inside the html?

It depends on what you are trying to do, but generally you can access anything referenced by your pc.Application instance in the same way:

   // for example let's find an entity and disable it in the hierarchy'My Entity').enabled = true;
1 Like

Let’s say I want to create a method outside playcanvas to get certain data. For example:

index html
var Test = pc.createScript('test');

Test.prototype.initialize = function()
{'test:getData', this.getData, this');

If it possible something like this?


var Colliders = pc.createScript('colliders');

Colliders.prototype.someMethod = function()
     //Some actions
     data = this.entity.getPosition();'test:getData', data);

You can do that but it does mean that you can’t add the Test script in the Editor and only at runtime.