How to modifiy variable from editor script (not runtime)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Strook
Posts: 70
Joined: Fri Nov 08, 2019 10:51 am

How to modifiy variable from editor script (not runtime)

Post by Strook »

Hello!

How can I modify a variable from an editor script at editor time?

Example: I have a variable "Foo" of type number, and a Editor script that needs to set this variable to a certain number at editor time.



Thanks!
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to modifiy variable from editor script (not runtime)

Post by Tony Li »

Hi,

At runtime, the dialogue database variables are copied to Lua variables, so you'd use DialogueLua.SetVariable().

At editor time, on the other hand, they're still just dialogue database variables. There is no Lua environment at editor time. You need a reference to your dialogue database. If you don't have one, EditorTools.FindInitialDatabase() will return the database that's assigned to the open scene's Dialogue Manager:

Code: Select all

DialogueDatabase db = PixelCrushers.DialogueSystem.EditorTools.FindInitialDatabase();
Then you can call DialogueDatabase.GetVariable() to get the variable and set its value:

Code: Select all

PixelCrushers.DialogueSystem.Variable variable = db.GetVariable("Foo");
variable.InitialFloatValue = 42;
User avatar
Strook
Posts: 70
Joined: Fri Nov 08, 2019 10:51 am

Re: How to modifiy variable from editor script (not runtime)

Post by Strook »

perfect, thanks! That's exactly what I was looking for 👍
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to modifiy variable from editor script (not runtime)

Post by Tony Li »

Glad to help!
Post Reply