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

Shadowing variables #265

Open
DoomTas3r opened this issue Oct 11, 2024 · 1 comment
Open

Shadowing variables #265

DoomTas3r opened this issue Oct 11, 2024 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@DoomTas3r
Copy link
Contributor

DoomTas3r commented Oct 11, 2024

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
Copy link
Contributor

manuq commented Oct 17, 2024

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.

@manuq manuq added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants