I am having some issues with converting a script from a legacy script to work with the new system.
The original code is:
pc.script.create('animateCamera', function (app) {
// Creates a new AnimateCamera instance
var AnimateCamera = function (entity) {
this.entity = entity;
};
AnimateCamera.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
var node = app.root.findByName("BlenderCamera");
var camera = app.root.findByName("CameraSceneOne");
camera.reparent(node);
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
}
};
return AnimateCamera;
});
And my conversion so far looks like:
var AnimateCamera = pc.createScript('animateCamera');
// Creates a new AnimateCamera instance
var AnimateCamera = function (entity) {
this.entity = entity;
};
AnimateCamera.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
var node = app.root.findByName("C4DCamera");
var camera = app.root.findByName("Camera");
camera.reparent(node);
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
}
};
But I’m getting errors.
I’m stuck at this and would really appreciate where I’ve gone wrong - still learning so annoying to come across simple issues like this but I’ll get there.
I have got to the below but receiving errors. Please forgive me still picking this all up and I’m so grateful for your help.
var AnimateCamera = pc.createScript('animateCamera');
AnimateCamera.prototype.initialize = function () {
var node = this.app.root.findByName("BlenderCamera");
var camera = this.app.root.findByName("Camera");
camera.reparent(node);
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
}
};
Debugging - is essential part of development, it involves investigating your application logic and inspecting state of code to figure out what went wrong.
Here we go, check what is on line 11, it says what an issue there. And it is SyntaxError.
Our Code Editor will highlight an issue there as well for convenience.
Thank you so so much @max@vaios and @yaustar - you helped me immensely not only with this issue but understanding how I should go about debugging and general coding practice!
For anyone who searches for this and needs the solution, this works:
var AnimateCamera = pc.createScript('animateCamera');
AnimateCamera.prototype.initialize = function () {
var node = this.app.root.findByName("BlenderCamera");
var camera = this.app.root.findByName("Camera");
camera.reparent(node);
};
AnimateCamera.prototype.update = function (dt) {
// Called every frame, dt is time in seconds since last update
AnimateCamera.prototype.update = function (dt) {
};
};