Assigning same value to multiple variables at once

Godot Version

3.5.3 and 4.2.1

Question

In python you can assign the same value to multiple variables at once.

a = b = c = 200

But when I try to do the same in Godot, whose coding language is based in Python, I get an error.
image

Isn’t there a way to do this in GDScript? I wanted to avoid having multiple lines of code or loops to assign the same texture to multiple objects.

Hey!

You should see gdScript as a standalone thing with it’s own features

Sure it was designed with python structure in mind and coded in C++ but it is a language by itself with unique pros and cons

You can have the general convention here :

I advise you to not have multiple instructions per line

Also keep in mind that it is in constant evolution and that you can follow and participate to it here:

Hope that helped, good luck!

That being said I feel like I didn’t really answer, how would I tackle the assignation of multiple sprite with the same texture:

I would have a class that act as a collection of Sprite with a setter method that assign to every registered Sprite

A mockup would be:

class_name SpriteAtlas

var sprites: Dictionary = {}

func add_sprite(p_to_add: Sprite2D) -> bool:
    var result = false

    if sprites.has(p_to_add.name):
        result = true
    sprites[p_to_add.name] = p_to_add


func set_common_texture(p_texture: Texture) -> void:
    for sprite in sprites:
        sprite.texture = p_texture

I don’t that on phone so it might be awful but something along those lines

I hope it gave you some ideas!