YarnSpinnerTool / YarnSpinner-Rust

The friendly tool for writing game dialogue in Rust
https://janhohenheim.itch.io/yarnspinner-rust-demo
Apache License 2.0
173 stars 15 forks source link

Variable not in storage when using `declare` but working when using `set` #204

Closed PraxTube closed 3 months ago

PraxTube commented 4 months ago

I am trying to get variables from yarn into Bevy. The following

let variable_storage = runner.variable_storage_mut();
let test_variable: i32 = variable_storage.get("$t").unwrap().try_into().unwrap();
variable_storage.set("$t".to_string(), (test_variable + 1).into());

works fine if I use

<<set $t = 0>>
<<custom_command>>

However I get the following error when I use

<<declare $t = 0>>
<<custom_command>>

gives

called `Result::unwrap()` on an `Err` value: VariableNotFound { name: "$t" }

I don't really see why the behaviour would differ. The variable works fine inside of yarn when using declare. The yarn docs also don't really mention any difference in this regard. I thought the only difference between declare and set is that the former doesn't allow to declare the same variable multiple times, but is this wrong? Are there other differences between these two commands?

janhohenheim commented 4 months ago

I think this mirrors the Unity behavior, but I'm not sure. define used to be a bit different in previous versions of Yarn Spinner and this might be a leftover from back then. There's a big possibility that Yarn Spinner V3 will address this. Will investigate :)

PraxTube commented 3 months ago

Okay so I kinda forgot that I was still on Bevy 0.12 (and yarnspinner 0.1), I just tested this on Bevy 0.14 and yarnspinner 0.3.1 and this works there.

janhohenheim commented 3 months ago

Great :D