Item variable names in dialogue

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
rjc
Posts: 3
Joined: Thu Feb 02, 2023 8:51 pm

Item variable names in dialogue

Post 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.
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Item variable names in dialogue

Post 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.
rjc
Posts: 3
Joined: Thu Feb 02, 2023 8:51 pm

Re: Item variable names in dialogue

Post 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".
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Item variable names in dialogue

Post 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.
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Item variable names in dialogue

Post 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"]))]
rjc
Posts: 3
Joined: Thu Feb 02, 2023 8:51 pm

Re: Item variable names in dialogue

Post by rjc »

Fantastic, thanks Tony. This looks exactly like what I was hoping for.
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Item variable names in dialogue

Post by Tony Li »

Glad to help!
Post Reply