Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
froggy96 opened this issue Dec 25, 2022 · 0 comments
Open
Assignees
Labels

Comments

@froggy96
Copy link

[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);
            }
        }
@codingseb codingseb added the bug label Dec 26, 2022
@codingseb codingseb self-assigned this Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants