endlessm / godot-block-coding

Block-based visual programming plugin for Godot
https://godotengine.org/asset-library/asset/3095
MIT License
278 stars 19 forks source link

Shadowing variables #265

Open DoomTas3r opened 2 weeks ago

DoomTas3r commented 2 weeks ago

What Happened

I thought, 'How can delta from every frame be obtained without creating that variable?' I created the variable with the exact name delta and printed the result which was a float. The debugger displays a warning that delta shadows the already-declared variable.

This unlocks a feature, but it can become a problem if the types don't match

image

Generated script:

extends Node2D

var delta: float

func _ready():
    delta = 0

func _process(delta):
    print((delta))

How to Reproduce

  1. Create a variable named delta
  2. Place an every frame block
  3. Attach a log text block to every frame
  4. Attach delta as input to log text
  5. Run the scene

Block Coding Plugin Version

v0.7.1

Godot Engine Version

v4.3

Operating System

No response

Logs or command-line output

W 0:00:02:0492   The local function parameter "delta" is shadowing an already-declared variable at line 3.
  <GDScript Error>SHADOWED_VARIABLE
  <GDScript Source>gdscript://-9223371985063508500.gd:9

Anything else?

No response

manuq commented 1 week ago

Yes, very good point. For variables maybe adding them all to a _block_coding_variables = {} dictionary would be an option.

Then we have the same issue when defining methods: the user can currently shadow a builtin method like Node2D rotate() using the "define method" block.