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

Extension Best Practices #70

Closed
tristanbob opened this issue Nov 22, 2020 · 3 comments
Closed

Extension Best Practices #70

tristanbob opened this issue Nov 22, 2020 · 3 comments

Comments

@tristanbob
Copy link
Contributor

tristanbob commented Nov 22, 2020

➡️ See the checklist of the best practices here ⬅️


Original discussion:

I have realized that the scene variables used in my extension are not locally scoped inside the extension. Instead, they share the same space that all scene variables share. This means that some of my simple names for scene variables could collide with something that the GDevelop user has assigned.

  1. Can you provide guidance on how variables should be named when used inside an extension? Someone gave an example that looked like this:
    "_MyExtensionMyVariableName"

  2. Is there any way to delete temporary scene variables that were used in an extension? (These should still follow the naming convention to prevent accidental overwriting and deletion)

@tristanbob tristanbob changed the title Guidance for naming of variables used by extensions? Guidance for naming of variables created by extensions? Nov 22, 2020
@4ian
Copy link
Collaborator

4ian commented Nov 22, 2020

Can you provide guidance on how variables should be named when used inside an extension? Someone gave an example that looked like this:
"_MyExtensionMyVariableName"

That's a good convention, also if you can put most of the variable inside a single structure variable with the name of your extension (and an underscore in front of it), that should greatly reduce the risk of conflicts.

This means that some of my simple names for scene variables could collide with something that the GDevelop user has assigned.

Yes, that's the risk. If you see an extension that uses a fairly obvious/common variable name, let me know and feel free to submit an updated extension.

Is there any way to delete temporary scene variables that were used in an extension? (These should still follow the naming convention to prevent accidental overwriting and deletion)

There is no easy way to remove a variable outside of a structure, which is kind of per design (in a game you avoid creating and destroying variables too much if you can). I think it's ok because it's giving at least one hint in the debugger to the end user that this variable was created and used - so you must be careful about not using it.

I think the proper answer to this would be to add support "extension variable" (with actions/conditions/expressions for variables scoped to extensions). With this, no more risk of conflict at all. I've created a card for this here: https://trello.com/c/CWL7Z9jB/463-add-support-for-extension-variables

That's the cleanest solution. In the meantime, let's be sure to use variables with a long prefix to avoid collisions :)

@4ian 4ian pinned this issue Nov 22, 2020
@tristanbob
Copy link
Contributor Author

I like your solutions, both short-term (unique names or a single structure with child variables) and long-term (variables that only exist inside the extension).

Thanks!

@4ian
Copy link
Collaborator

4ian commented Feb 17, 2021

Closing this as we have the checklist now :)

@4ian 4ian closed this as completed Feb 17, 2021
@Bouh Bouh changed the title Guidance for naming of variables created by extensions? Extension Best Practices Aug 17, 2021
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

No branches or pull requests

2 participants