Skip to content
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

[STCC-229] variables not referenced correctly #156

Conversation

oiduh
Copy link
Contributor

@oiduh oiduh commented Mar 20, 2020

Previously, if a global variable was referenced in a sprite (that is not the background), a new local variable with the same name was added to the sprite. As a result the pocket code program could only access the local variant of the variable and scripts didn't work as they were intended to.
Since the background in scratch has no local variables, it serves as a container for all global variables. In the code all global variables are stored in self.project.userVariables and local variables in self.sprite.userVariables. In case a variable within a sprite cant be accessed, it has to be a global one and it has to be referenced correctly, so the script can use it.
In order to prevent confusion in the future, comments were added to explain how to access the variables.

@oiduh oiduh changed the title STCC-229_variables_referenced_correctly [STCC-229] variables not referenced correctly Mar 20, 2020
Copy link
Contributor

@gregbauer gregbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work as there is no possibility for sprites other than the background sprite to set/change global variables. The check "catrobat.is_background_sprite(self.sprite)" may be redundant here. Just ask for local variables first (as these probably shadow global variables? Needs to be tested?) and then check for global variables (in all sprites, not only the background sprite)
Here is the project I tested your changes with: https://scratch.mit.edu/projects/380191404/

Also, I think you should remove the config.ini from the commit.?

@oiduh oiduh force-pushed the STCC-229_not_referencing_global_variables_correctly branch from 3a8122f to b359347 Compare March 28, 2020 15:09
@oiduh
Copy link
Contributor Author

oiduh commented Mar 28, 2020

You're right. I changed the code accordingly and adjusted the comments. The project you used initially for the test should also work now correctly.

@AntiDog AntiDog merged commit c3b8ccd into Catrobat:develop Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants