Page 1 of 1

Item variable names in dialogue

Posted: Thu Feb 02, 2023 9:02 pm
by rjc
Hi, I'm just getting my footing with plugin and am liking the experience so far, but I am coming up against one particular issue during my initial testing.

I have configured an item "Orb" within the items database and an item variable called "test.item" with its intial value set to the "Orb" item.

How would I obtain the name of this item during dialogue? Some other posts I have found lead me to believe I could accomplish this using the following snippet:

Code: Select all

[lua(Item[Variable["test.item"]].Name)]
but this throws an error at runtime:

Code: Select all

Dialogue System: Lua code 'return Item[Variable["test.item"]].Name' threw exception 'Lookup of field 'Name' in the table element failed because the table element itself isn't in the table.'
My assumption was that

Code: Select all

Variable["test.item"]
would return the ID of the item, which I could then use to index into the Item database and extract the name from the resulting item, but the error leads me to believe this is the part of the code that is failing.

Any suggestions would be appreciated. Cheers.

Re: Item variable names in dialogue

Posted: Fri Feb 03, 2023 8:08 am
by Tony Li
Hi,

Let's break it down to see what's going on. What do the markup tags below show?

Code: Select all

[lua(Variable["test.item"])]

Code: Select all

[lua(Item["Orb"].Name)]
Also, please make sure the correct database (containing "Orb" and "test.item") is assigned to the Dialogue Manager's Initial Database field.

Re: Item variable names in dialogue

Posted: Fri Feb 03, 2023 8:46 am
by rjc
Thanks Tony.

The inital database has been assigned so that looks good.

The first markup tag displays as "2" (which I assume is the ID of the item) and the second displays as "Orb".

Re: Item variable names in dialogue

Posted: Fri Feb 03, 2023 8:56 am
by Tony Li
Hi,

I assume the "test.item" variable is of type Item? If so, then you're correct; this is the ID. Unfortunately there's no one-line built-in translation of IDs to item names in Lua. That would be good to add. I'll add that in the next release and post a patch here later today. In the meantime, you could change "test.item"'s Type to Text and set it to "Orb", or use the patch later today.

Re: Item variable names in dialogue

Posted: Fri Feb 03, 2023 2:28 pm
by Tony Li
This patch adds Lua functions ActorIDToName(), ItemIDToName(), and QuestIDToName():

DS_ItemIDToNamePatch_2023-02-03.unitypackage

You can use it like this:

Code: Select all

[lua(ItemIDToName(Variable["test.item"]))]

Re: Item variable names in dialogue

Posted: Sat Feb 04, 2023 3:08 am
by rjc
Fantastic, thanks Tony. This looks exactly like what I was hoping for.

Re: Item variable names in dialogue

Posted: Sat Feb 04, 2023 9:58 am
by Tony Li
Glad to help!