YarnSpinnerTool / YarnSpinner

Yarn Spinner is a tool for building interactive dialogue in games!
https://yarnspinner.dev
MIT License
2.3k stars 201 forks source link

TryGetValue<T> called with type IConvertible. #382

Closed staneta closed 7 months ago

staneta commented 7 months ago

What is the current behavior?

I have a custom VariableStorage. ContinueDialogue calls the function TryGetValue<T>(string variableName, out T result) with type IConvertible. This never happened in 2.3.

Please provide the steps to reproduce, and if possible a minimal demo of the problem:

Setup a dialogue and play it to the end? Here's an example node that has this behaviour (all of my nodes have this behaviour):

title: MerchantGreeting
---
<<if visited("MerchantGreeting")>><<endif>>
Merchant: A new <wiggle a=0.005>hunter</wiggle>, huh? #line:02d4fc4 
Merchant: Times are weird. #line:02b9287 
===

What is the expected behavior?

I think TryGetValue should only be called with types: string, float, bool? Let me know if that's an incorrect assumption.

Please tell us about your environment:

Other information

I printed out a variable name and type in TryGetValue and here's the stacktrace:

Variable: $Yarn.Internal.Visiting.SmallGirlGreeting  Type: System.IConvertible
UnityEngine.Debug:Log (object)
EasySaveVariableStorage:TryGetValue<System.IConvertible> (string,System.IConvertible&) (at Assets/Scripts/Dialogue/EasySaveVariableStorage.cs:36)
Yarn.VirtualMachine:RunInstruction (Yarn.Instruction)
Yarn.VirtualMachine:Continue ()
Yarn.Dialogue:Continue ()
Yarn.Unity.DialogueRunner:ContinueDialogue (bool) (at ./Library/PackageCache/dev.yarnspinner.unity@2.4.0/Runtime/DialogueRunner.cs:1142)
Yarn.Unity.DialogueRunner:DialogueViewCompletedDismissal (Yarn.Unity.DialogueViewBase) (at ./Library/PackageCache/dev.yarnspinner.unity@2.4.0/Runtime/DialogueRunner.cs:1217)
Yarn.Unity.DialogueRunner/<>c__DisplayClass111_0:<DismissLineFromViews>b__0 () (at ./Library/PackageCache/dev.yarnspinner.unity@2.4.0/Runtime/DialogueRunner.cs:1202)
BubbleLineView/<>c__DisplayClass19_0:<DismissLine>b__0 () (at Assets/Scripts/Dialogue/BubbleLineView.cs:101)
DG.Tweening.Tween:OnTweenCallback (DG.Tweening.TweenCallback,DG.Tweening.Tween)
DG.Tweening.Tween:DoGoto (DG.Tweening.Tween,single,int,DG.Tweening.Core.Enums.UpdateMode)
DG.Tweening.Core.TweenManager:Update (DG.Tweening.Tween,single,single,bool)
DG.Tweening.Core.TweenManager:Update (DG.Tweening.UpdateType,single,single)
DG.Tweening.Core.DOTweenComponent:Update ()

I'm also attaching my EasySave3 custom variable storage if it's of any value: EasySave3Storage.txt

desplesda commented 7 months ago

Hi! Yes, the assumption that TryGetValue will only be called with bool, float and string is not quite accurate.

While it's true that bools, floats and strings are the only types in Yarn Spinner, the Dialogue calls TryGetValue with IConvertible type parameter whenever it needs to fetch a variable's contents. This is because the Dialogue doesn't know or care what type the variable will be, and IConvertible is the common denominator.