How to run a separate scripts function in dialogue

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
krockhunter
Posts: 4
Joined: Sun Nov 28, 2021 11:25 pm

How to run a separate scripts function in dialogue

Post by krockhunter »

Hi, I am quite new to Pixel Crushers Dialogue System and I am trying to run this line of code

Player.MyInstance.GainXP(50);

when a certain response is chosen by the player during a conversation.
I tried placing it into the script part of the dialogue option but received this error

Code: Select all

Dialogue System: Lua code 'Player.MyInstance.GainXP(50);' threw exception 'Lookup of field 'MyInstance' in the table element failed because the table element itself isn't in the table.'
How do I go about having it so when I click on a certain response, I can get this bit of code to run?

Also, is there a way to move the use message to be displayed above the thing we are going to talk to instead of at the top of the screen? I know I can move it to be center left/right etc but I think it would be better to be above the person we are about to interact with.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to run a separate scripts function in dialogue

Post by Tony Li »

Hi,
krockhunter wrote: Mon Nov 29, 2021 12:34 amHi, I am quite new to Pixel Crushers Dialogue System and I am trying to run this line of code

Player.MyInstance.GainXP(50);

when a certain response is chosen by the player during a conversation.
I tried placing it into the script part of the dialogue option but received this error

Code: Select all

Dialogue System: Lua code 'Player.MyInstance.GainXP(50);' threw exception 'Lookup of field 'MyInstance' in the table element failed because the table element itself isn't in the table.'
How do I go about having it so when I click on a certain response, I can get this bit of code to run?
Thanks for using the Dialogue System!

Please see the video tutorial How To Connect Your Own Code To Lua:


krockhunter wrote: Mon Nov 29, 2021 12:34 amAlso, is there a way to move the use message to be displayed above the thing we are going to talk to instead of at the top of the screen? I know I can move it to be center left/right etc but I think it would be better to be above the person we are about to interact with.
Yes. Add an instance of the 'Basic Standard Usable UI' prefab as a child of your thing you're going to talk to, and position it above the thing. You can restyle it to look however you want.
krockhunter
Posts: 4
Joined: Sun Nov 28, 2021 11:25 pm

Re: How to run a separate scripts function in dialogue

Post by krockhunter »

Yes. Add an instance of the 'Basic Standard Usable UI' prefab as a child of your thing you're going to talk to, and position it above the thing. You can restyle it to look however you want.
I'm not sure how to get that to work, I have placed the prefab as a child of the person I am talking to but I am not 100% sure where to go from there.
Unity_2021-11-30_11-11-06.png
Unity_2021-11-30_11-11-06.png (66.34 KiB) Viewed 749 times
Unity_2021-11-30_11-13-27.png
Unity_2021-11-30_11-13-27.png (4.74 KiB) Viewed 749 times
This is what I've done so far for the person I am talking to, I assume I have to do something with the Usable action there but I'm not sure. When I play the game it does the normal text at the top of the screen.
Unity_2021-11-30_11-15-06.png
Unity_2021-11-30_11-15-06.png (97.33 KiB) Viewed 749 times
What is my next step from here?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to run a separate scripts function in dialogue

Post by Tony Li »

Hmm, if a GameObject with a Usable component has a Basic Standard Usable UI (really, anything with a Standard Usable UI component) in its child hierarchy, then when you select the GameObject it should show it instead of the default screen space UI.

Also, add a Selector Use Standard UI Elements component to the same GameObject as your Selector / Proximity Selector if you haven't already. This component enables the Selector / Proximity Selector to be aware of Standard Usable UIs and also whatever Standard UI Selector Elements component(s) that are in the scene. (The default Dialogue Manager prefab has an Instantiate Prefabs component that instantiates a copy of Basic Standard UI Selector Elements.)
krockhunter
Posts: 4
Joined: Sun Nov 28, 2021 11:25 pm

Re: How to run a separate scripts function in dialogue

Post by krockhunter »

So it looked like the Selector Use Standard UI Elements component was what I was missing from the player. Thanks for letting me know, I would have gone insane trying to figure this stuff out.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to run a separate scripts function in dialogue

Post by Tony Li »

Sorry, that's an easy one to overlook. In version 2.2.23, when you add a Selector or Proximity Selector component, the inspector will show a button to add a Selector Use Standard UI Elements component.
Post Reply