[SOLVED] Error when getting data from a different script

I am trying to be able to get data from a script (textinput.js) from the script (saveText.js) and I received an error when trying to do so.

I am trying to get the data ‘inputext’. Please tell me what I have done wrong and how to fix it. I would highly appreciate it.

The project link: PlayCanvas 3D HTML5 Game Engine

The error I received:

[[saveText.js?id=228177194&branchId=6c8ce5fe-55e0-441a-9373-69cefa0f109a:13]](https://playcanvas.com/editor/code/1341716?tabs=228177194&line=13&col=47&error=true): Uncaught TypeError: Cannot read properties of undefined (reading 'inputext')

TypeError: Cannot read properties of undefined (reading 'inputext')
at ElementComponent. (https://launch.playcanvas.com/api/assets/files/scripts/saveText.js?id=228177194&branchId=6c8ce5fe-55e0-441a-9373-69cefa0f109a:13:47)
at ElementComponent.fire (https://code.playcanvas.com/playcanvas-2.7.4.dbg.js:1728:27)
at ElementInput._fireEvent (https://code.playcanvas.com/playcanvas-2.7.4.dbg.js:127784:22)
at ElementInput._onElementMouseEvent (https://code.playcanvas.com/playcanvas-2.7.4.dbg.js:127687:27)
at ElementInput._handleUp (https://code.playcanvas.com/playcanvas-2.7.4.dbg.js:127498:15)

Hi @VisionsKlips!

On line 13 of your saveText.js script you should use scriptAInstance instead of this.scriptAInstance.

image

1 Like

Thank you, @Albertos. I will try and tell you if it works.

1 Like

It works but I am not getting the input in the console. Could you please help me with this and by the way I will be online tomorrow as I am getting offline now.

Yes, I already saw you didn’t update the input variable correctly in the other script. So, please check which variable you use and how you update it.

1 Like

Thank you, @Albertos for helping me. I fixed the issue by adding the .textinput variable from textinput.js into the update function instead of the initialize function.

1 Like