'Local' Conversation Variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

'Local' Conversation Variables

Post by Mackerel_Sky »

Hi,

I'm looking at trying to implement some kind of local variable for only one conversation that the player can have. For example, my player can turn on a computer, so I would set a bool called "TurnedOn" or something. If they interact with it again, the dialogue system would check if TurnedOn is true and play some other dialogue. This bool would only apply for any computer prefabs that they might interact with, and have no relevance to any other conversation they might have.

Is there a way to implement something similar to what I have in mind? There are a lot of interactables in my project, so I'm scared I will get quickly overwhelmed.

Thanks!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: 'Local' Conversation Variables

Post by Tony Li »

You can add a variable in the Variables section or add a custom field to the computer actor in the Actors section.

If you use a variable, you can name it something like "Computer.TurnedOn". This way you can add other computer-related variables in the future, such as "Computer.Locked" and "Computer.Overheated", and the variable names will make it clear that they're all related to the computer. In the Variables section, you can sort by name so all "Computer.*" variables are grouped together, and you can even set a filter to only show "Computer." variables. In the computer conversation/Dialogue System Trigger, you can check Variable["Computer.TurnedOn"].

Alternatively, you can add a custom field to the actor associated with your computer conversation(s). To add a custom field, expand the actor's All Fields section, and click the "+" button. In the computer conversation/Dialogue System Trigger, you can check Actor["Computer"].TurnedOn.
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Re: 'Local' Conversation Variables

Post by Mackerel_Sky »

Hey Tony,

Thanks for the help, it worked in the situation i specified but I should have been a bit more clear on what I had in mind- both solutions work for the entire game, so if one computer instance is turned on, when the player turns another one on the variable is already true so it will go straight to TurnedOn dialogue. Is it possible to have each instance store a value of TurnedOn so if one turns on the others remained turned off?

Off the top of my head a solution would be to generate a component in the instance that stores the bool, and access it using sequencer commands, but I figured there might be a simpler alternative.

Thanks,
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: 'Local' Conversation Variables

Post by Tony Li »

I was about to recommend adding a script to the Dialogue Manager that has two C# methods: one to record that a specific computer has been turned on, and another that checks if a computer has already been turned on. Then register them with Lua.

However, I think a simpler way is to have each Dialogue System Trigger set a unique number or name for each computer. Use Actions > Run Lua Code to set a Lua variable. You don't have to define this variable ahead of time in the dialogue database. Example:

okComputer1.png
okComputer1.png (27.56 KiB) Viewed 767 times

Then check that variable in your computer conversation:

okComputer2.png
okComputer2.png (17.94 KiB) Viewed 767 times

Note the unusual syntax:

Code: Select all

Variable[Variable["ComputerID"]] ~= true
Since your Dialogue System Trigger set Variable["ComputerID"] to "Computer_1", this is equivalent to:

Code: Select all

Variable["Computer_1"] ~= true
As with Variable["ComputerID"], you do not need to define Variable["Computer_1"] ahead of time.
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Re: 'Local' Conversation Variables

Post by Mackerel_Sky »

Hey Tony,

Thanks for your help. The reason why I didn't go with the sequencer command option is that I don't really want to save game data between scenes using my own game save system (which is on its first iteration and very clunky - literally just found out DS offers a save system which I'm very eager to get into now) when Dialogue System's database can support dialogue/story progression in its own database. I was able to add another Dialogue System Trigger to the game object to use the correct on/off sprite depending on whether the player turned it on and left/returned to the scene. I'm really happy with how it turned out!

Maybe an even better solution would be just to save the items in Dialogue System's save system?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: 'Local' Conversation Variables

Post by Tony Li »

It's pretty easy to extend the Dialogue System's save system to save other things, such as your items. Just copy the saver template script (located in Plugins/Pixel Crushers/Common/Templates), fill in code where indicated, and add the script to your game/scene. You can look at the code for any of the existing savers, such as PositionSaver or ActiveSaver, to see how they work.
Post Reply