Page 1 of 1

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

Posted: Thu Mar 10, 2016 3:59 am
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

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

Posted: Thu Mar 10, 2016 7:02 am
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".

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

Posted: Thu Mar 10, 2016 7:45 am
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!

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

Posted: Thu Mar 10, 2016 1:03 pm
by Tony Li
Great!