Godot Version
4.5
Question
How do i save thing to a list in such a way that i can use a for loop to modify them all, weather that be changing their position to a randomized new position at a button press, or doubling them( i imagine for tree in treelocs is the best way to do that???). pretty much, what i imagine my code is doing right now is just checking the value of their position and saving that to a list, but what id like to be able to do is save them in a way that lets me change things about them. ALSO, if yall got any tips for getting better at scripting id appreciate
extends Node
#i wanna save their position to the list then randomize their position
# or maybe do something like double them.
# but my problem is, i think it saves the value of .position to the list, not any way to actually modify the tree
var Treelocs = []
var Treecount = 0
var Hp = 100
func Newsprite(sprite_2d: Sprite2D) -> Sprite2D:
var new_sprite2d: Sprite2D = sprite_2d.duplicate()
new_sprite2d.scale = Vector2(randf(), randf())
new_sprite2d.position = Vector2(randf_range(0,1150), randf_range(0,650))
Treelocs.append(new_sprite2d.position)
add_child(new_sprite2d)
return new_sprite2d
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$Label.text = " NOOB NOOB NOOB NOOB NOOB NOOB NOOB "
$Label.modulate = Color.GREEN
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _input(event):
if event.is_action_pressed("MyAction"):
Treecount = Treecount + 1
Newsprite($Node2tree/Sprite2D)
elif event.is_action_pressed("Gamerbutton"):
print("There are :", Treecount,"Trees")
print("The trees are at", Treelocs)
elif inpit.is_action_pressed("bac"):
for loc in Treelocs # this is where i get confused
else :
pass