Variable returning undefined in Update()

    start() {
        window.addEventListener('wheel', this.OnMouseWheelChanged, { passive: false });

    OnMouseWheelChanged(event) {
        this.scrollDelta = 35;

    update() {

Hi there! I set the number to 35 and console.log, and it comes out correctly. However, if I log the same variable in Update(), it comes out as undefined. Any ideas?

[Original Post on Discord](

*by user 95852307077406720*

its because you need to bind your method “OnMouseWheelChanged” to the class instance of your script. this is undefined in OnMouseWheelChanged

Change it to:

window.addEventListener('wheel', this.OnMouseWheelChanged.bind(this), { passive: false });

You can also use the value stored in this.context.input for the scrolldelta in update directly

Thank you, I apologise about these silly questions, this is a totally new paradigm to me haha

by user 95852307077406720

No problem

That’s not a silly question tho :sweat_smile: was very confusing / strange to me too when I first learned about it

For quite a long time actually until I worked more with all the js stuff.
E.g. when you write a function using arrow notation it auto-binds (e.g. () => { console.log(this) } vs function() { console.log(this) })

Or you can call a function with, firstArgument, secondArgument) which is the same as myFunction.bind(this)(firstArgument, secondArgument)