(Solved!) Using Registered Functions to update Adventure Creator's Inventory

Announcements, support questions, and discussion for the Dialogue System.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

(Solved!) Using Registered Functions to update Adventure Creator's Inventory

Post by CodePrincess »

Hi, Tony! I hope you and yours are enjoying a safe and healthy holiday season!

So I bought your program (Finally! :-D) and Adventure Creator last Black Friday.
Sis prefers handling logic through the Dialogue System as exclusively as possible, so I
made a custom Lua command that will let her add items to AC's runtime inventory from a dialogue entry.

It mostly works, but I get this log error:
Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
Tracing it, it looks like problematic object is a system exception or its object?
Adventure Creator Bridge Error.png
Adventure Creator Bridge Error.png (47.76 KiB) Viewed 1425 times
I don't know if this is relevant, but I did create instances of the item in both Dialogue System and Adventure Creator's Inventories.

If you need any more information, or if you think this is a problem for Adventure Creator, please let me know.
I look forward to hearing your opinion on this situation.
Last edited by CodePrincess on Sat Dec 14, 2019 12:32 pm, edited 1 time in total.
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by Tony Li »

Hi,

Thanks for buying the Dialogue System! :-)

If you prefer, with the Adventure Creator integration you can add and remove items using these steps:

1. In the Dialogue Editor's Templates section, define a custom Number field named Count:

acItems1.png
acItems1.png (21.55 KiB) Viewed 1422 times

2. In the Dialogue Editor, create an item in the Quests/Items section for each Adventure Creator item:

acItems2.png
acItems2.png (5.22 KiB) Viewed 1422 times

3. Use the "..." dropdowns in the Conditions and Script fields to change an item's Count. This is the number of items that are in the player's inventory:

acItems3.png
acItems3.png (21.38 KiB) Viewed 1422 times

When a conversation starts, the AdventureCreatorBridge component will update the Count values of the Dialogue System's items. When the conversation ends, the AdventureCreatorBridge will use the Dialogue System's Count values to update Adventure Creator.


However, if you want to use your own Lua function, that's perfectly fine, too. In that case, please click on the error message and press Ctrl+C to copy its details to the clipboard. Then paste them into a reply here.

BTW, in the next update (which I'm trying to get out by the end of next week), you'll be able to make your custom Lua functions available in the "..." dropdowns. Here's an example of what it looks like with a custom function AddHammers(#):

customLua.png
customLua.png (7.73 KiB) Viewed 1422 times
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by CodePrincess »

BTW, in the next update (which I'm trying to get out by the end of next week), you'll be able to make your custom Lua functions available in the "..." dropdowns.
Oooo! Oooo! That's so cool! That'll make Sis' life so much easier! :D :D :D


I tried the Item.Count approach you suggested, following your steps carefully, and somehow got the same error as my registered function. Here's the debug log entry you asked for (Well, it's from the "Item.Count" attempt, actually):
Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
PixelCrushers.DialogueSystem.AdventureCreatorSupport.AdventureCreatorBridge:SyncLuaToInventory() (at Assets/Pixel Crushers/Dialogue System/Third Party Support/Adventure Creator Support/Scripts/AdventureCreatorBridge.cs:501)
PixelCrushers.DialogueSystem.AdventureCreatorSupport.AdventureCreatorBridge:SyncLuaToAdventureCreator() (at Assets/Pixel Crushers/Dialogue System/Third Party Support/Adventure Creator Support/Scripts/AdventureCreatorBridge.cs:366)
PixelCrushers.DialogueSystem.AdventureCreatorSupport.AdventureCreatorBridge:OnConversationEnd(Transform) (at Assets/Pixel Crushers/Dialogue System/Third Party Support/Adventure Creator Support/Scripts/AdventureCreatorBridge.cs:168)
UnityEngine.Component:BroadcastMessage(String, Object, SendMessageOptions)
PixelCrushers.DialogueSystem.ConversationModel:InformParticipants(String, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:208)
PixelCrushers.DialogueSystem.ConversationController:Close() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:131)
PixelCrushers.DialogueSystem.ConversationController:OnFinishedSubtitle(Object, EventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:241)
PixelCrushers.DialogueSystem.ConversationView:FinishSubtitle() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:391)
PixelCrushers.DialogueSystem.ConversationView:HandleContinueButtonClick() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:363)
PixelCrushers.DialogueSystem.ConversationView:OnConversationContinue(IDialogueUI) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:348)
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
PixelCrushers.DialogueSystem.AbstractDialogueUI:OnContinueConversation() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Abstract/Dialogue/AbstractDialogueUI.cs:366)
PixelCrushers.DialogueSystem.AbstractDialogueUI:OnContinue() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Abstract/Dialogue/AbstractDialogueUI.cs:356)
PixelCrushers.DialogueSystem.StandardUIContinueButtonFastForward:OnFastForward() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Effects/StandardUIContinueButtonFastForward.cs:67)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/2019.2.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
Sheesh, that's a mouthful! :shock:
I'm so looking forward to seeing that new manager feature in action! 8-)
Thank you for your help!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by Tony Li »

Hi,

If you're using your own custom Lua functions to manage AC's inventory, you can untick this checkbox on the AdventureCreatorBridge component:
  • Sync Settings > From Dialogue System (On Conversation End) > Copy Dialogue System To AC Items
That should completely bypass the issue.

If you'd like to manage AC's inventory using the Item["Banana"].Count method I described above, then we'll need to figure out why the "Copy Dialogue System to AC Items" operation is logging an error. In this case, would you mind importing this updated AC integration package? (Back up your project first, just to be safe.) It adds a "Debug" checkbox to the AdventureCreatorBridge component. Please tick the checkbox.

DS_AdventureCreatorSupport_2019-12-13.unitypackage

When a conversation ends, it will log this line to the Console:

Code: Select all

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory
Then it will log 4 lines like below for each item:

Code: Select all

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Name=Prop sword
Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: AC ID=0
Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Count=0
Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: Name=Prop sword, ID=0, Count=0
and a 5th line if the item amount changed.

Reproduce the problem and reply with the lines it logs. You don't have to paste in the entire stack trace like that mouthful above. It won't get through all of the items. You might be able to identify which item it got stuck on by looking at the AC Game Editor window's Inventory section.

If you prefer, you can send a copy of your project to tony (at) pixelcrushers.com. I'll be happy to take a look at it directly if you like.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by CodePrincess »

Okay. Here are the logs:
Dialogue System: Lua(Item["Badge"] = { Name="Badge", Description="", Is_Item=true, AC_ID=0, Count=0 })
UnityEngine.Debug:Log(Object)

Dialogue System: Lua(Item["List_of_Numbers"] = { Name="List of Numbers", Description="", Is_Item=true, AC_ID=1, Count=0 })
UnityEngine.Debug:Log(Object

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Name=Badge
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: AC ID=0
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Count=1
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: Name=Badge, ID=0, Count=1
UnityEngine.Debug:Log(Object)

Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Name=List of Numbers
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: AC ID=1
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Count=0
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: Name=List of Numbers, ID=1, Count=0
UnityEngine.Debug:Log(Object)
I still can't tell what happened. The items were created in the same order, so they should have the same IDs.
Wait. I just realized you can initialize Items in both the Variables and Quests/Items screens. I tried initializing my items in
the Variables screen, but nothing changed. Should they only be initialized in one tab or the other?

Have you noticed anything else? Well, good night, and I'll see you in the morning!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by Tony Li »

Thanks! We're getting somewhere. This confirms that the error is happening in the method that tries to update Adventure Creator.

Please import this updated package, reproduce the problem one more time, and reply with the debug output:

DS_AdventureCreatorSupport_2019-12-14.unitypackage

I think this will pinpoint the issue.

BTW, did "Object reference not set to an instance of an object" come out only once, for Badge? Or did it come out again for List of Numbers?
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by CodePrincess »

BTW, did "Object reference not set to an instance of an object" come out only once, for Badge? Or did it come out again for List of Numbers?
List of Numbers was added to the inventory via AC interaction object. It gets no errors.

I'm updating the debug system now. I'll be back soon with your data.
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by CodePrincess »

Dialogue System: Lua(Item["Badge"] = { Name="Badge", Description="", Is_Item=true, AC_ID=0, Count=0 })
UnityEngine.Debug:Log(Object)

Dialogue System: Lua(Item["List_of_Numbers"] = { Name="List of Numbers", Description="", Is_Item=true, AC_ID=1, Count=0 })
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Name=Badge
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: AC ID=0
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Count=1
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: Name=Badge, ID=0, Count=1
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: KickStarter.player is null
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: Name=List of Numbers
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.SyncLuaToInventory: AC ID=1
UnityEngine.Debug:Log(Object)

Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: Name=List of Numbers, ID=1, Count=1
UnityEngine.Debug:Log(Object)
There. Now this is the result of trying to add both badge and list of numbers to the inventory using Item.Count. No errors were listed, but no items appeared in the inventory.

Thank you for getting me through this!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by Tony Li »

Hi,

I think this update should fix the problem:

DS_AdventureCreatorSupport_2019-12-14a.unitypackage

This is the smoking gun:
Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: KickStarter.player is null
For whatever reason, AC's KickStarter.player variable isn't set in your scene. It may be that the player prefab isn't tagged 'Player' or that there's no player in the scene. In any case, the bridge should now handle it properly in this case by adding the items to the current player without needing to access KickStarter.player.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Using Registered Functions to update Adventure Creator's Inventory

Post by CodePrincess »

It works!
This is the smoking gun:
Dialogue System: AdventureCreatorBridge.UpdateAdventureCreatorItem: KickStarter.player is null
Oh. Oh, I can explain that:

Since the game strictly plays in first person view, I had no player character, so I didn't think to add a player object before running the game. I had no idea they were that important. :oops:

You saved the day again, Mr. Li! :D
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
Post Reply