-
Notifications
You must be signed in to change notification settings - Fork 659
Object Factory Error - variable used before it's declaration #6155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the feedback. On start can trigger events and can have pauses (which can also trigger some type of events). This is the reason events are registered first. I understand this breaks the above scenario. I am unsure of easy solution here. |
Sounds like you could use an init block in addition to on start. |
I'm pretty sure I could workaround it by making it a conditional with some behind-the-scenes logic. I was able to replicate the up, down, and hold events in MakeCode, so should be able to do it in the extension too. User-generated Jacdac clients is an experiment rather than a need, so I won't be pushing that idea to completion. I'm curious if you think an init block would be worthwhile for a future release though. Seems like this might be a niche situation if this is the first time it has come up. |
Like init event handler which is guaranteed to be registered first before all other event handlers? |
Yes, a block for initializing variables at the top of the code, basically. To guarantee they'll be available for events. |
@ssande-fwd we have the
you can also make your event nestable if you prefer so that you can place it after the variable declaration within on-start by using the |
Describe the bug
I use an object factory to generate a Jacdac button client in on start. I have a custom on button down block for the button client I've created. The code is compiled such that the on button down code comes before the button client is generated. This leads to the error "variable used before it's declaration"
To Reproduce
Expected behavior
I am able to use blocks associated with an object that is created in on start.
Screenshots

Additional context
Why isn't on start code put at the start of the JavaScript compilation? Manually putting it there resolves the error.
The factory block is officially documented here https://makecode.com/defining-blocks
The text was updated successfully, but these errors were encountered: