ExpressionEvaluator icon indicating copy to clipboard operation
ExpressionEvaluator copied to clipboard

[Suggestion] AssignVariable in Script Evaluation (Not in Declraration)

Open froggy96 opened this issue 2 years ago • 0 comments

[CASE] 0. Declare Variable First uint value = 1;

  1. The variable type is unit at this point.

  2. Assign a value to it value = 10;

  3. Now the type of 'value' is int (as engine evaluates 1 as int)

  4. Variable type changed.

[Solution] Change AssignVariable method:

        if (Variables.ContainsKey(varName) && Variables[varName] is StronglyTypedVariable stronglyTypedVariable)
        {
                  ...
        }
        else
        {
            try
            {
                if (Variables[varName].GetType() == value.GetType())
                {
                    Variables[varName] = value;
                }
                else
                {
                    Variables[varName] = Convert.ChangeType(value, Variables[varName].GetType());
                }
            }
            catch (Exception exception)
            {
                throw new InvalidCastException(exception.Message, exception);
            }
        }

froggy96 avatar Dec 25 '22 12:12 froggy96