Accessing Quest variable from lua inside the db editor

Announcements, support questions, and discussion for the Dialogue System.
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Accessing Quest variable from lua inside the db editor

Post by bluebuttongames »

Hi Tony,

So I have a field in some of my quests that's a boolean called "Return".

What would I put in the dialogue tree script field to progress if this particular value of this particular quest is set to true?

Thanks,

BB
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Accessing Quest variable from lua inside the db editor

Post by nathanj »

If you want the dialogue to be allowed or blocked by the boolean, in the Condition field you would have:

Code: Select all

Variable["return"] == true


Or, if you want to change the boolean value, you can use the script field to make changes to variables and quest states, etc.

Code: Select all

Variable["return"] = true

- it's best to use the drop-down menu for adding fields to conditions and scripts.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing Quest variable from lua inside the db editor

Post by Tony Li »

Similarly to Nathan's reply, if this is a field in your quest rather than a variable, you'll need to check the Quest[] table instead of the Variable[] table. The "..." dropdowns don't go so far as to handle custom quest fields, so you'll have to type it manually. For example:
  • Conditions: Quest["Holy_Grail"].Return == true
Note that non-alphanumeric characters such as blank spaces should be replaced by underscores, so "Holy Grail" becomes Quest["Holy_Grail"].

If the quest doesn't have a Return field, it will return nil, which is the "undefined" value.
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Re: Accessing Quest variable from lua inside the db editor

Post by bluebuttongames »

Perfect, thanks guys.
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Re: Accessing Quest variable from lua inside the db editor

Post by bluebuttongames »

I have a similar problem where a conversation string spits this out:

Hey there Variable["player_name"]

As that's what's in the dialogue editor. Is there something special I need to do to get this as a runtime value?

Thanks,

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

Re: Accessing Quest variable from lua inside the db editor

Post by Tony Li »

Hi,

If that's a dialogue entry's Dialogue Text or Menu Text field, or a quest's description or entry fields, then the Dialogue System should automatically replace [var=player_name] with the value of the variable player_name.

(Note that the format is [var=varName].)

If it's another field or a string of your own, call FormattedText.ParseCode to get a version in which [var=varName] and [lua(code)] tags have been replaced with their values:

Code: Select all

string s = FormattedText.ParseCode("Hey there [var=player_name]");
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Re: Accessing Quest variable from lua inside the db editor

Post by bluebuttongames »

That still didn't work, maybe I'm explaining myself poorly.

Here's what I have in the Dialogue entry, it spits this out literally in-game.
Attachments
dialogue.PNG
dialogue.PNG (21.49 KiB) Viewed 1411 times
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Accessing Quest variable from lua inside the db editor

Post by Tony Li »

Hi,

Try changing your Dialogue Text to: Hey [var=player_name]
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Re: Accessing Quest variable from lua inside the db editor

Post by bluebuttongames »

Hey, I know it's been a while. I still can't get this working even with that syntax.

I've tried these in my dialogue text field:

"
Variable["player_policeStars"] hours should do it.

[var="player_policeStars"] hours should do it.

[var=player_policeStars] hours should do it.

"
None of those do anything other than the raw code coming through in the text. Is there something I'm missing?
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Re: Accessing Quest variable from lua inside the db editor

Post by bluebuttongames »

Never mind, it was the way this was being parsed at the text box end.
Post Reply