Hello, all. I am working with some code to change text depending on a variable.
Here is the code.
if (phase === 1) {
this.cstxt1.element.text = 'Hello, I am Leanana';
this.cstxt2.element.text = 'Hi, what do you do?';
// this.cstxt2.setPosition(-237.094,-69.018,-403.066);
this.cstxt3.element.text = 'Do you have any tasks for me?';
};
if (phase === 2) {
this.cstxt1.element.text = 'I am a fighter piolot.';
this.cstxt2.element.text = 'Do you have any tasks for me?';
// this.cstxt2.setPosition(-237.094,-69.018,-403.066);
this.cstxt3.element.text = 'What do you fly?';
};
if (phase === 3) {
this.cstxt1.element.text = 'I fly a cruiser.';
this.cstxt2.element.text = 'Have a good day!';
// this.cstxt2.setPosition(-237.094,-69.018,-403.066);
this.cstxt3.element.text = 'Do you have any tasks for me??';
};
if (phase === 4) {
this.cstxt1.element.size = 0.01;
this.cstxt1.element.text = 'Yes! I left a battery at one of the gaurd towers.';
this.cstxt2.element.text = 'Decline';
// this.cstxt2.setPosition(-237.094,-69.018,-403.066);
this.cstxt3.element.text = 'Accept';
decision = 1;
};
Lines 2, 9, and 24 don’t give me an issue, but line 16 does. This is the error: [cutscenemagager.js?id=176180148&branchId=d716681b-5f85-49bf-bd12-abd5d124b363:109]: Cannot read properties of null (reading ‘element’)
TypeError: Cannot read properties of null (reading ‘element’)
at Cutscenemagager.update (https://launch.playcanvas.com/api/assets/files/Scripts/UI/cutscenemagager.js?id=176180148&branchId=d716681b-5f85-49bf-bd12-abd5d124b363:109:25)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:107514:22)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:107548:15)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:108308:52)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:108326:11)
at ComponentSystemRegistry.fire (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:1668:21)
at AppBase.update (https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:71874:19)
at https://code.playcanvas.com/playcanvas-1.70.2.dbg.js:72927:20
Another weird thing that happens is that line runs, but then line 16 doesn’t run. I have tried to fix it, but I have not been able to. Any ideas?