Variable increments when I press any button, not the ones I want to.

Announcements, support questions, and discussion for the Dialogue System.
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Variable increments when I press any button, not the ones I want to.

Post by olikante »

Hey! I tried to find a topic that would describe my problem but I couldn't so I decided to write this post.

My project is a point-and-click type of game without a player in the scene (no walking character on the screen). Via dialogue, we get a quest to collect objects by clicking on buttons spread different scenes.
It works, even too good cause it reacts on ANY button. I tried to set up layers and tags by it doesn't work.

I'm using a selector for my mouse position placed on the main camera.

Image
Image

On the objects that suppose to be collected, I have:
- usable,
- increment on destroy script,
- dialogue trigger system.

Image

I'm trying to solve it for two days, so I would appreciate any help. ;)
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

Hi,

What do you mean by "it reacts on ANY button"?

Do you mean an input button (e.g., left mouse button) or a UI button?

What if you set it up like this?

1. Selector: Remove Flower1B from OnSelectedUsable() event.

2. Collectible object: Remove Dialogue System Trigger. Configure Usable's Events > OnUse() Event to deactivate the GameObject.
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

Oh, yes, sorry. UI button.
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

Thanks for your help. I did what you suggested but there is no difference. The variable is incrementing when I click on any UI button.. Hm...
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

If each collectible object has a UI button, you don't need to use the Selector and Usable components. Configure the UI Button's OnClick() event to deactivate the GameObject.

However, you want to use the Selector to show what's currently under the mouse cursor, you can keep the Selector and Usable. In this case, remove the Dialogue System Trigger, and remove any events from the Usable's OnUse() event. The Selector will only show the selection; it won't actually response to clicks since the UI Button will handle that.

I see that your Increment On Destroy component's Increment amount is 5. This means that when you click on a flower, it will add 5 to the variable. Is that what you intend? If not, try setting it to 1.
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

It is set to 5 for testing reasons, but my problem is that I would like that variable to change only when I click on the button in the green frame, but it increments when I click on buttons in the pink frames.

Image
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

If the variable should only increment when the player clicks on the green area, what is the purpose of the UI Button? Can you remove it?
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

It just makes it easier to communicate that click event to other scripts as well.

However, do you know what is the exact problem with the situation here?
Why is the variable reacts on each UI button even if they don't have any components connected to the dialogue system?
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

I don't know. Maybe it's coincidence, and the UI button simply overlaps the area that's covered by the Usable. If that's the case, the UI button isn't doing anything, but clicking on the area around the UI button is, completely unrelated, causing the Selector to use the Usable.

What do you need to communicate to other scripts? Can you do the same thing with the Usable component?

Get rid of either the Usable component or the UI button. It sounds like having both of them is causing confusion. If you really need both of them, it's certainly possible to do. In that case, let me know why you need both.
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

1. I created a quest about collecting (clicking on specific UI buttons in the scene) objects.

Image

2. I defined a variable to track the quest's progress.

Image

3. The user is entering a dialogue that starts a quest. It works.
4. The user needs to go to another scene and click on specific buttons to influence the variable.

Image

5. When they clicked on enough buttons then they can go back to the quest giver and finish the quest.

Image
Image

The problem is that if I click on the wrong button (not flower ;) ) under FlowerFields 2 component, under Canvas obviously, the variable is incremented as well.

Image
Image

Let me know if sth is unclear.
Last edited by olikante on Sun Feb 21, 2021 10:28 am, edited 1 time in total.
Post Reply