What am I doing wrong!

Hi all, going crazy over this one :sweat_smile:

I’m using this great music player and for the most part it’s working as intended. However for some reason, despite my code being the exact same in two places - in one of the places, the volume fade script I made won’t work.

Genuinely don’t know what I could be missing because they are identical in structure (unless I overlooked something). The only difference is that the one place it does work is within a clip in the main project, as opposed to the broken one which is located right in the main project (see screenshots).

The default+update scripts where it won’t work:


The default+update scripts where is does work:


I don’t know that much code so you could ask @FroggyWadd or @noobfield

it looks like you set cook volume to 0 but did not do the same for lowasbg. if that is not the problem can I have the wick file?

Oh! If I’m late, sorry, but you need to add this. to lowasbg.

When you tell JS to define lowasbg, it says:

Hmm? No var, no this or window. Set it to the scope.

The scope is a thing to try to stop you from accessing things that you shouldn’t.

An easy fix would be:

  • using var to define variables that are local.
  • using this. to define and use variables that will stay on the clip.
var myThing = "thing"; // Right syntax for local variables
if (myThing === "thing") console.log("My thing is a thing!");

this.ourThing = "thing"
if (this.ourThing === "thing") console.log("Our thing is a thing!");

// Update
if (myThing === "thing") console.log("My thing is a thing!"); // will not print
console.log(myThing === undefined) // true

if (this.ourThing === "thing") console.log("Our thing is a thing!"); // will print

I’m sorry, but I’m not sure I’m following your example using this. for this particular issue ^^; I have certainly used it throughout the project with much simpler context (if (this.hits());, this.remove();, etc.) but I am struggling to see where it would fit in here since I thought that by adding the sound manager to the bottom, I should be good to go with using it globally.

I still tried to put this. in, but anywhere I put it near lowasbg it throws an error.

Also, I should mention that I had temporarily fixed it but after refreshing the editor not only did that temporary fix stop working, but I found that the editor cannot see any of my sound classes at all and even the area that was once working had stopped working… all of them throw this same error of not being defined, despite them being defined in my declarations layer.

Oh! You just, put let before it:

// i hope i don't need to add another educational snippet here.
let object = {}
let object.thing = "thing" // does not work!
object.thing = "thing" // does work!

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Ok, I’ll look into it when I have time.

1 Like

I think I solved my issue! I started adding window. to my sound variables in place of this., combined with refreshing the browser (I was having issues with the editor) and it seemed to resolve the errors being thrown/restored functionality.


Thanks for helping me walk through my thoughts :slight_smile:

1 Like

Nice!!! sorry I couldn’t look at it, I’ve been busy.

2 Likes