0 votes

Hey! To keep it short and simple, im working on a "shopkeeping" game, i have display furniture nodes in the game, and these nodes have "slots" where you can display sellable items.

You can click on an area on this slots to interact with them, this brings up an interface where you can select an item to display and sell there.

Problem is...
The selection interface is a "sibling" separate from the display (Not a child, not a parent) it's easy to "call" from the display cases to the selection interface, but then Im having trouble with the interface knowing from which node and slot the interaction came from.

In the display case code, the lines related to the interaction are these:

func _on_Item0Area_input_event(camera, event, click_position, click_normal, shape_idx):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT and event.pressed == true:
            get_parent().get_node("HUD/Displayinteract").show()
            get_parent().get_node("HUD/Displayinteract").call("interactingwith", "0", $item0.global_transform)

"Interactingwith" is a func in the selection interface
"0" is the slot in the display case
and
"$item0.global_transform" is a Position3D where the chosen item will be displayed

But what happens when i have more than 1 display case around the shop? How can the interface know which display case "slot 0" is the one "interacting" with it.

Thanks in advance!

Godot version 3.3 Stable
in Engine by (298 points)

Can you minimize your description to only essential implementation details, because now it's very unclear, what's you concrete question about?

Normally, for a callee to know who's called, caller should pass itself as a function argument (like self).
Another approach (care should be taken) - is to use something like global var last_clicked_caller.

I know, believe me i tried haha, but english is not my native language and even so sometimes it's hard to express yourself clearly when talking about code.

To avoid repeating myself, check the answer i posted to this same question where i clear things up and solve the issue, at least in a way.

Still, i wont mark the question as "Solved", because there may be better methods.

1 Answer

0 votes

I always end up solving my issues right after "giving up" and asking the community haha.

Anyways here's how i did it...

On the display case's side:

func _on_Item0Area_input_event(camera, event, click_position, click_normal, shape_idx):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT and event.pressed == true:
            get_parent().get_node("HUD/Displayinteract").show()
            get_parent().get_node("HUD/Displayinteract").call("interactingwith", get_path(), "0", $item0.global_transform)

Basically, when you click on the display slot 0 in the case, you make the selection interface visible, and call the function "Interactingwith" on it, with these variables:

getpath() = carries over the absolute node path to the display case
"0" is the slot in that display case
and
"$item0.global
transform" is the position of the Position3D node that tells where the item will appear.

The selection interface side is too long and irrelevant to the specific question, but so far this works.

by (298 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.