Skip to content

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

Open
@froggy96

Description

@froggy96

[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);
            }
        }

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions