Variable references, maybe symbolic variables???, possible or no?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jitterbeetle

If i have this (in Godot 4.0.1)
Let us call these Line2D.

var boxes: Dictionary = {
      'blubox' = $box/big,
      'redbox' = $box/small

Can I do something later with it? I’ve tried but have been unable.

For example:

for i in boxes:
      boxes[i].add_point(Vector2(10.0, 13.1), boxes[i].get_point_count())

It seems this is not possible and I think these would be called symbolic references. But maybe there’s a way that I can’t see???

Thank you.

p.s. please kill recaptcha with fire&gasoline

What do you mean “I’ve … been unable”, “it is not possible” and what do you mean “symbolic references”?
This code seem perfectly reasonably, although the values in the dictionay are not typed, so I don’t know if add_point() and get_point_count() exists.

zhyrin | 2023-03-22 17:40

Unable means “I’m not able to make it work”.

Give an example of a properly typed dictionary using my example please.

Thanks for the interest.

jitterbeetle | 2023-03-22 19:11

Well, you not being able to make it work is unfortunately not a concrete enough issue that I can help you with.
If you would describe the intended behaviour, the actual behaviour and show all relevant code sections, then that would be something people could help you with.

There are no typed dictionaries in godot (unfortunately), I might have been misleading with that, what I meant is by this snippet alone I can’t confirm if the issue is that you are calling methods that are not present on the types of $box/big and $box/small.

zhyrin | 2023-03-22 19:29

Well I thought since you weren’t familiar with symbolic references that the question was over your head a little. No problema.

Hmm, typed dictionaries might require symbolic references…, but I’m not certain.

Do you have an idea of how a typed dictionary would look or work? I’m curious.

Thanks for the interest.

jitterbeetle | 2023-03-22 19:56

Alright, it seems like you are not working towards a solution here.

zhyrin | 2023-03-22 20:03

:bust_in_silhouette: Reply From: Enfyna

I think this works as expected.


extends Control
@onready var boxes: Dictionary = {
		'blubox' = $box/big,
		'redbox' = $box/small
func _ready():
	boxes['blubox'].add_point(Vector2(10.0, 13.1), boxes['blubox'].get_point_count())


[] # boxes['blubox'].points
[] # $box/big.points
[(10, 13.1)] # boxes['blubox'].points
[(10, 13.1)] # $box/big.points