Skip to content

Making IVariables more defensive

Compare
Choose a tag to compare
@grofit grofit released this 07 Jun 14:02
· 90 commits to master since this release

Summary

Currently when interacting with IVariables it is expected that you will be using the indexer and it will throw if the variable doesn't exist. While this is fine for the most part, it can catch devs unaware, especially with the pattern for extensions on the variables allowing you to access the data like properties i.e myItemTemplate.Variables.QualityType().

So as currently this could blow up on you if:

  • The QualityType variable is not set when you are getting it
  • The QualityType is not an int when you try to get it

It felt like this could be a bit problematic for people who are just trying to get on and be productive, so we are changing the way these default helper extensions work by using Convert.ToXXX rather than manual casts, and also using GetVariable on the variables vs Variables[VariableType].

This comes at a minor performance cost, but it will not be noticeable unless you are calling these methods hundreds of thousands of times per frame/update, and if performance is an issue you are still able to write your own optimised conventions/extensions that directly access the variables.