How to run a separate scripts function in dialogue
Posted: Mon Nov 29, 2021 12:34 am
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
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.
Re: How to run a separate scripts function in dialogue
Posted: Mon Nov 29, 2021 9:07 am
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
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?
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.
Re: How to run a separate scripts function in dialogue
Posted: Mon Nov 29, 2021 7:16 pm
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 (66.34 KiB) Viewed 816 times
Unity_2021-11-30_11-13-27.png (4.74 KiB) Viewed 816 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 (97.33 KiB) Viewed 816 times
What is my next step from here?
Re: How to run a separate scripts function in dialogue
Posted: Mon Nov 29, 2021 8:32 pm
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.)
Re: How to run a separate scripts function in dialogue
Posted: Mon Nov 29, 2021 9:00 pm
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.
Re: How to run a separate scripts function in dialogue
Posted: Mon Nov 29, 2021 9:14 pm
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.