Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Faxikon |
Hello peeps,
I am quite new to Godot and am making a 2D Grid based Game kind of like a chess game.
Everything worked quite well until i stomped over a problem i really can’t figure out the solution for.
So first of all i am creating a instance and add this as a child to my scene, when i use the left mouse button.
But also creating a dictionary with the intend to get ahold of that object later through the dictionary.
func _input(event):
if event is InputEventMouseButton:
match event.button_index:
BUTTON_LEFT:
var new_obj = Class.instance()
self.add_child(new_obj)
var pos = calc_mouse_to_grid()
obj_position_dict[pos] = new_obj
But when i want to actually get ahold of the object through the dictionary i dont really know how to call the methods of this object.
BUTTON_RIGHT:
var pos = calc_mouse_to_grid()
if obj_position_dict.has(pos):
"""place where i want to call the methods
of the Class the obj
(accessed through obj_position_dict[pos])
belongs to.
"""
print(obj_position_dict[pos])#testing purpose
For testing purpose i added print(obj_position_dict[pos])
,
which prints something like this [Node2D:22091]
. I figured, that the number is the individual instance ID of this object, but i didn’t jet figured how to use it, because i always get [Node2D:22091]
returned and therefore start at the beginning.
I hope someone understands what the problem is and how to solve it or at least has a work around for this.
But i want to have it as dynamic as it can get. So no pre defining arrays or something like that.
Thank you!
It’s printing its ID Because it’s the correct object.
Now obj_position_dict[pos].the_method_you_want_to_call(and_its_arguments)
.
hinasis | 2018-09-12 07:40