# Mouse pointer over a hotspot

**URL:** <https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400>\
**Category:** Questions\
**Created:** [August 6, 2022, 4:46pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400 "2022-08-06T16:46:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rene\_Hamann](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rene_hamann/32/29268_2.png) [@Rene\_Hamann](https://forum.defold.com/u/Rene_Hamann)\
**Post date:** [August 6, 2022, 4:46pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/1 "2022-08-06T16:46:33Z")

</div>

Hello.

After many frustrating days of trial and error and several deinstallations and reinstallations of Defold, I decided to do one last try before giving up at all.

I’m trying to create a point-and-click adventure. In my opinion this type of game is just a background image with one or more hotspots. If the player clicks on a hotspot, one or more actions will be executed (e.g. walk to a given position, say something, take an object and put it into the inventory).

I was able to create the following collection:

 ![screenshot1](https://forum-defold-uploads.b-cdn.net/original/3X/4/b/4bc800af92d53e2eef8081207b648c496899db9b.jpeg)

As you can see there are two hotspots (which are game objects with a collision component). Then there is the pointer game object (which has also a collision component). The hotspots and the pointer have a Type of Trigger.

The pointer has the following script. If the pointer and a hotspot collide, the label beside the pointer shows the description of the hotspot.

 ![screenshot2](https://forum-defold-uploads.b-cdn.net/original/3X/9/3/93637da1c2d7b7f0d7fc0290d134d704a13f24a5.png)

The problem is now that this is not efficient at all. In a real point-and-click adventure there could be hundreds of hotspots. I shouldn’t use hundreds of if-else statements just to show the description of a hotspot. And don’t forget the problem that I am not able to handle the click on a hotspot at this time. I just don’t know how to do that.

Another problem is that the real game would have dozens of scenes. I think it would be a good idea to use a collection for every scene (scene 1 = scene1.collection, scene 17 = scene17.collection, …). Then I could add the hotspots for every scene as game objects with a collision component.

But does all of that really work with the pointer script above?

I just feel really overwhelmed.

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [August 6, 2022, 7:19pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/2 "2022-08-06T19:19:50Z")

</div>

You just need a table. Use the hashed IDs as the keys, and either just the label text, or (more useful), a table with whatever data you want to associate with the hotspot.

Something like this (untested):

```lua
local hotSpotDatas = {
	[hash("/hotspotExit")] = { label = "Exit" },
	[hash("/hotspotComputer")] = { label = "Computer" },
}

function on_message(self, message_id, message, sender)
	if message_id == hash("trigger_response") then
		if message.enter then
			local hotSpotData = hotSpotDatas[message.other_id]
			if hotSpotData then
				local label_text = hotSpotData.label
				label.set_text("/pointer#label", label_text)
			end
		else
			label.set_text("/pointer#label", "")
		end
	end
end

```

> [@Rene\_Hamann](#):
>
> I am not able to handle the click on a hotspot at this time. I just don’t know how to do that.

All you need for clicking on things, is to know _what_ you clicked on (and if you clicked on anything). You’re already doing the collision detection, so you just need to save some information (store it in a ‘self’ property) about what the cursor is currently colliding with. Then, in your on\_input function, if it’s a click, check the info you saved, and if the cursor is colliding with something, do something with it.

> [@Rene\_Hamann](#):
>
> Another problem is that the real game would have dozens of scenes.

The short anwser: Yes, it’ll be fine.  
The long answer: I wouldn’t worry about this at the moment. Just take it one step at a time. Do things the quickest, dirtiest, easiest way you can think of first, and if you run into problems, then you fix it. No use speculating about problems that you have no information about.

---

<div class="post-metadata">

**Author:** ![88.josh](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/88.josh/32/20137_2.png) [@88.josh](https://forum.defold.com/u/88.josh)\
**Post date:** [August 6, 2022, 9:12pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/3 "2022-08-06T21:12:35Z")

</div>

> [@Rene\_Hamann](#):
>
> hundreds of hotspots

It is possible for one person to make a point and click game. In fact, of all the possible games, I’d say it’s a great one to get started with. It will be fairly simple to learn how to point, display information, click, put items into an inventory, etc… It’s much simpler than other games and it’s a great project for a first-timer.

With that said… yes, making video games sometimes involves putting the names of hundreds of different variables into a list. Sorry!! I really, really, hope you don’t give up and keep working on your project. Best of luck!

> [@ross.grams](#):
>
> ```lua
> local hotSpotDatas = {
> [hash("/hotspotExit")] = { label = "Exit" },
> [hash("/hotspotComputer")] = { label = "Computer" },
> }
> 
> ```

Learning about lists and how to use them with ipairs is very very important. Because it means you avoid a lot of manual repetition. Here’s a simple example that I am just working on now with a list of GUI nodes.

```lua
function init(self)
	msg.post(".", "acquire_input_focus")
	self.nodes = {"A","B","C","AB","BC","AC","Fstop","Bstop","B1","B2","B3","B4","F1","F2","F3","F4"}
end

function on_input(self, action_id, action)
	if self.on then
		for k,v in ipairs(self.nodes) do
			if gui.pick_node(gui.get_node(v), action.x, action.y) and action.pressed then
				gui.animate(gui.get_node(v), "color", vmath.vector4(1,1,1,1), 1, 0.1)
				msg.post("controller#script", v, {"pressed"})
			else
				gui.set_color(gui.get_node(v), vmath.vector4(0,0,0,0.5))
			end
		end
	end
end

```

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [August 7, 2022, 7:12am UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/4 "2022-08-07T07:12:36Z")

</div>

There’s some good threads on this topic! Marco Giorgini is experienced in creating point and click adventures in Defold.

Here he shares the source of one of his jam games:

> [@The Mysterious Gear Chest (point-n-click game for #advjam2022)](https://forum.defold.com/t/the-mysterious-gear-chest-point-n-click-game-for-advjam2022/71161):
>
> Hi everybody, as usual, I’m here to showcase my advjam entry - made with Defold: a more or less two-hours long point-n-click pixel-art adventure game I’ve done in 14 days - featuring three different playable characters and a mysterious story about an unexpected archeological discovery, ancient gods and books. [hometitle] [image1] [image2] [image3] Official game page: [https://marcogiorgini.itch.io/the-mysterious-gear-chest](https://marcogiorgini.itch.io/the-mysterious-gear-chest) This time I’ve decided to release code & resources (with different lic…

Here he talks a bit about his workflow:

> [@A Weekend at Villa Apate](https://forum.defold.com/t/a-weekend-at-villa-apate/68504):
>
> Hello everybody, I’ve entered even this year AdvJam (a 14-days jam for an adventure game) with a game made with Defold, called A Weekend at Villa Apate. It’s a point’n’click pixel art game - more or less 20-30 minutes long as gameplay I developed onto my DAGS framework on Defold fantastic engine. [hall] If you want to give it a try you can find it here: [https://gamejolt.com/games/AWeekendatVillaApate/615569](https://gamejolt.com/games/AWeekendatVillaApate/615569) If you try it and if you want, feedbacks would be welcome! [BORING TEXT STARTS HERE] …

Marco has made more point and click jam games so I encourage you to browse his post history.

---

<div class="post-metadata">

**Author:** ![anon95708182](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@anon95708182](https://forum.defold.com/u/anon95708182)\
**Post date:** [August 7, 2022, 8:27am UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/5 "2022-08-07T08:27:50Z")

</div>

> [@Rene\_Hamann](#):
>
> I decided to do one last try before giving up at all.

Please, don’t give up, this would be a pity! Your background looks so beautiful.

---

<div class="post-metadata">

**Author:** ![Rene\_Hamann](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rene_hamann/32/29268_2.png) [@Rene\_Hamann](https://forum.defold.com/u/Rene_Hamann)\
**Post date:** [August 8, 2022, 3:46pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/6 "2022-08-08T15:46:36Z")

</div>

Your tips were quite helpful. I’m now able to click on a hotspot and the engine returns not only the id of the hotspot but also it prints a custom text on the console.

And you’re absolutely right about doing things the quickest, dirtiest, easiest way at first. If it works, it works.

---

<div class="post-metadata">

**Author:** ![Rene\_Hamann](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rene_hamann/32/29268_2.png) [@Rene\_Hamann](https://forum.defold.com/u/Rene_Hamann)\
**Post date:** [August 8, 2022, 3:47pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/7 "2022-08-08T15:47:35Z")

</div>

Thanks to you, too, for your helpful tips.

---

<div class="post-metadata">

**Author:** ![Rene\_Hamann](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rene_hamann/32/29268_2.png) [@Rene\_Hamann](https://forum.defold.com/u/Rene_Hamann)\
**Post date:** [August 8, 2022, 3:50pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/8 "2022-08-08T15:50:32Z")

</div>

I’ve found Marcos point-and-click adventure before and downloaded the Defold project. But I have to confess that his project is far beyond my capabilities. I understand very little how he has done it. Maybe after several years. 😉

---

<div class="post-metadata">

**Author:** ![Rene\_Hamann](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rene_hamann/32/29268_2.png) [@Rene\_Hamann](https://forum.defold.com/u/Rene_Hamann)\
**Post date:** [August 8, 2022, 7:33pm UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/9 "2022-08-08T19:33:39Z")

</div>

It’s not mine. It’s from a game called Deponia. I just needed a placeholder.

---

<div class="post-metadata">

**Author:** ![anon95708182](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@anon95708182](https://forum.defold.com/u/anon95708182)\
**Post date:** [August 9, 2022, 5:01am UTC](https://forum.defold.com/t/mouse-pointer-over-a-hotspot/71400/10 "2022-08-09T05:01:20Z")

</div>

> [@Rene\_Hamann](#):
>
> It’s not mine. It’s from a game called Deponia. I just needed a placeholder.

😄 I thought it looked vaguely familiar.

> [@Rene\_Hamann](#):
>
> I’m now able to click on a hotspot and the engine returns not only the id of the hotspot but also it prints a custom text on the console.

Brilliant. Looking forward to your game, point and clicks are so cool!
