phaserjs / phaser-editor-issues

Phaser Editor's bug tracker.
0 stars 0 forks source link

Feature: Prevent invalid variable names in the inspector #41

Closed scottwestover closed 1 month ago

scottwestover commented 1 month ago

One feature that I think would be useful for new users of the tool, or even people newer to programming would be to disallow adding variable names that are not valid, or to show some type of validation error in the GUI if an invalid variable name is used.

In the inspector, if the variable name is set to 1, if you try running your game, it will fail due to the code that is generated:

// 1
const 1 = this.add.image(640, 288, "dino");

This makes sense why it fails, but this is not immediately apparent to the end user until they dive into the code, or until they are familiar with the GUI.

Steps to reproduce:

  1. Update the variable name for a game object to be 1 in the inspector.
  2. Save your scene changes and then start your game.
  3. Game will not load and browser developer console shows the error.
  4. When you view the code in the IDE, we see the error right away.

Example Screenshots:

Screen Shot 2024-10-04 at 9 14 10 AM Screen Shot 2024-10-04 at 9 14 21 AM Screen Shot 2024-10-04 at 9 14 31 AM

Note: I ended up running into this issue when I uploaded image assets that just had numbers for the filename, example: 1.png, 2.png, 3.png, etc., and since the default variable name uses the filename, my variables were invalid right away.

Basic project as example: bug_example.zip

PhaserEditor2D commented 1 month ago

Fixed. If the name starts with a number, it prepends a _ character, like in _1.