[SOLVED] Using a variable as a string in the Quest[] list?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Ders
Posts: 18
Joined: Thu Mar 10, 2016 3:53 am

[SOLVED] Using a variable as a string in the Quest[] list?

Post by Ders »

I'm trying to create a "modular" dialogue tree where there will be information given based on a global variable that will be set with the quest name. So the dialogue tree will be filled in with it's description and such.

Now, I had it working if I did it like this (harcoded):

Code: Select all

Quest["Name_of_Quest"].Description
But I want it to have the dynamic quest lookup with the variable so I tried this:

Code: Select all

Quest[Variable["Name_Of_Quest"]].Description
and this doesn't work.

So in the Dialogue Text of one of the node I have:

Code: Select all

[lua(Quest[Variable["CurrentQuest"]].Description)]
and this throws an error:
Dialogue System: Lua code 'return Quest[Variable["CurrentQuest"]].Description' threw exception 'Lookup of field 'Description' in the table element failed because the table element itself isn't in the table.'
Any idea how I can solve this? I'm kind of new and I can't see what I'm doing wrong.
Thanks in advance
Last edited by Ders on Thu Mar 10, 2016 7:47 am, edited 1 time in total.
User avatar
Tony Li
Posts: 22106
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using a variable as a string in the Quest[] list?

Post by Tony Li »

Hi,

Make sure your variable's value has underscores in place of blank spaces, quotes, and other special characters.

The "index" into arrays such as the Quest array (that is, the part inside the [ ] square brackets) must have underscores in place of blank spaces etc.

Let's use the Feature Demo's "Assassinate the Emperor" as a concrete example.

You can get the quest description like this:

Code: Select all

Quest["Assassinate_the_Emperor"].Description
(Note the underscores in place of blank spaces.)

The trick is to make sure Variable["CurrentQuest"] is equal to "Assassinate_the_Emperor" with underscores:

Code: Select all

Variable["CurrentQuest"] = "Assassinate_the_Emperor"
Then you can use this in Dialogue Text:

Code: Select all

[lua(Quest[Variable["CurrentQuest"]].Description)]
and it will be equivalent to this:

Code: Select all

[lua(Quest["Assassinate_the_Emperor"].Description)]
If you need the "clean" quest name, it's kind of roundabout but you can use this:

Code: Select all

[lua(Quest["Assassinate_the_Emperor"].Name)]
It returns "Assassinate the Emperor".
Ders
Posts: 18
Joined: Thu Mar 10, 2016 3:53 am

Re: Using a variable as a string in the Quest[] list?

Post by Ders »

Thanks for the reply! I figured it out in the meantime. It was indeed the problem that my quest name had spaces and I was thinking that the system would catch that for some reason (which was stupid). Removed spaces and everything is working correctly!
User avatar
Tony Li
Posts: 22106
Joined: Thu Jul 18, 2013 1:27 pm

Re: [SOLVED] Using a variable as a string in the Quest[] list?

Post by Tony Li »

Great!
Post Reply