Hi,
It drives me crazy
Hey, i think either you have multiple scripts with same names or your script is corrupted.
If there are multiple scripts, you can simply delete all except one and that should work.
there is one script with this name
Can you share the project @abouzarp ? Looks like you’ve just got something mis configured
this is the script:
pc.script.create(‘messageReceiver’, function (app) {
return class MessageReceiver {
initialize() {
console.log(“MessageReceiver initialized and ready to receive messages.”);
window.addEventListener("message", (event) => {
if (event.origin !== "url) return;
const data = event.data;
if (data.type === "changeEntityState") {
const entity = app.root.findByName(data.entityName);
if (entity) {
entity.enabled = data.newState === "active";
console.log(`Entity "${data.entityName}" state changed to "${data.newState}".`);
} else {
console.log(`Entity "${data.entityName}" not found.`);
}
}
});
}
};
});
yes sure, how to share?
Send me a link and add MARK_SNAP to the project
Try this
const MessageReceiver = pc.createScript('MessageReciever')
MessageReceiver.prototype.initialize = function (app) {
console.log("MessageReceiver initialized and ready to receive messages.");
window.addEventListener("message", (event) => {
if (event.origin !== "http://blazingfallgames.com") return;
const data = event.data;
if (data.type === "changeEntityState") {
const entity = app.root.findByName(data.entityName);
if (entity) {
entity.enabled = data.newState === "active";
console.log(`Entity "${data.entityName}" state changed to "${data.newState}".`);
} else {
console.log(`Entity "${data.entityName}" not found.`);
}
}
});
};
it’s working, thanks a lot
could u explain the solution for me, I’m not very good at scripting though
You were creating the script incorrectly. In general just create a new script and add your code to the initialize()
in the boilerplate code that’s autogenerated.
thanks, noted