Publishing on PlayCanvas issue

Link to the editor PlayCanvas | HTML5 Game Engine
When I publish my game, and press the play button, the scripts don’t work, how do I fix this?
Thank you!

They don’t work how?

@Bradley_Pelletier @Albertos this is a known error in this class template.

[SOLVED] Cannot play published game - Help & Support - PlayCanvas Discussion

This is a repetitive post that has the following issue in the template given to the students.

Usually, when you’re in the main menu, you can press Space to start the game or ESC to view the credits. However that doesn’t work when you start the game via the start button.

@Bradley_Pelletier Are you switching scenes using the method above. If so this will not work.

They are:

https://playcanvas.com/editor/code/999598?tabs=115882438&line=11

1 Like

I just switched the window.open with the this.app.scenes.changeScene(‘Some Scene Name’);
It worked but now a different script completely bugged out

This is what stopped working after I changed the scene script
[ScoreUpdate.js?id=117761240&branchId=db850bed-a8d9-4da1-88cc-0b60acd38da5:9]: Uncaught TypeError: Cannot set properties of undefined (setting ‘text’)

It worked perfectly before I changed the scene script

Hi @Bradley_Pelletier!

You have attached the startGame.js to two entities, so everything in that script is executed twice. Please be aware of that.

Check also the topic below after you applied the suggested changes, because it looks like you use the same template.

2 Likes

I added that bit of code but the scene doesn’t load its frozen on the playcanvas loading screen

image

Ok, Everything works now except that the scripts don’t work when you play the game via the play button.

@Bradley_Pelletier I think your last question has also been answered in this forum. I can’t locate it currently but it has been in the last few days.

@Bradley_Pelletier Here is the area in your script that has issue currently.

var Destroy = pc.createScript('destroy');

// initialize code called once per entity
Destroy.prototype.initialize = function() {

};

// update code called every frame
Destroy.prototype.update = function(dt) {
Asteroid.prototype.update = function(dt) {
    // Get the player
    var player = this.app.root.findByName("Ship"); // Replace "Ship" with whatever your player's name is 
    // Clone the asteroid's position 
    var distance = this.entity.getPosition().clone();
    // Subtract the player's position from this asteroid's position
    distance.sub(player.getPosition());
    // Get the length of this vector
    if(distance.length() > 10){ //Some arbitrary threshold 
        this.entity.destroy();
    }
};
};

There is already a method called destroy. The script name must be changed.

1 Like