Forum rules - please read before posting.

Bug (?) with ActionList: Set Parameter and Global Variables

edited August 2 in Technical Q&A

Hi

Assumption: All action list access to a global variable that links to a custom script results in the variable beining synced prior to use. (IE gated by a OnDownload event). If this isnt the case skip to the bottom :)

Bug: When the Set Parameter action copies a global variable into a parameter, it will not always sync the global variable first.

Approx test case:
1. Create an integer global variable that links to a custom script and script sets initial value is checked.
2. Add a component to sync the global variable much like VariableLinkingExample.cs (confirming your GVar ID is correct, listen/respond to the OnDownload event, etc)
3. Create a Action List Asset
4. Add a Integer Parameter to the action list
5. Add Set Parameter action inside the action list asset, where

  • Parameter is the action list asset parameter name from #4
  • New Value is set to "Copied from Global Variable"
  • Variable is the Global Variable from #1
  1. Set a break point in the OnDownload for #2
  2. Run the action list

Expected: The BP is hit (ie the variable is synced and the OnDownload event is fired by AC))
Result: The BP is not hit (ie the variable is not synced; the last value is was synced to will be copied)

Suggested Fix: On ~line 218 of ActionParamSet.cs::GlobalVariables.GetVariable() pass true to synchronize

else if (setParamMethod == SetParamMethod.CopiedFromGlobalVariable)
{
    ActionParameter parameter = GetParameterWithID (parameters, globalVariableParameterID);
    if (parameter != null && parameter.parameterType == ParameterType.GlobalVariable)
    {
        runtimeVariable = parameter.GetVariable ();
    }
    else
    {
        runtimeVariable = GlobalVariables.GetVariable (globalVariableID, true); // Dont use default parameter, explicitly set
    }
}

This works in my simple test case, but no idea if its correct/safe.

Note:

  • Many other actions WILL sync the variable (which made this tricky to actually reproduce, for example: ActionList Check will trigger a sync. Having a action list parameter of type Global Variable with the correct variable will sync it when the list is run (which still isnt the safest approach, but it did make this bug trickier to track down)
  • globalVariableParameterID is -1 meaning parameter.GetVariable() is not called. parameter.GetVariable would result in a sync. Im, not 100% certain on how globalVariableParameterID is set as I dont fully understand SmartFieldStart()
  • The test case is for an int, but I suspect it applies to all global variable types.

Finally:
If this assumption isnt correct and AC dosent guarantee syncing og global variables before use, then I can make sure the GVar variable is manually set in code, but this is both a pain and (IMO) bug prone (but not complaining, this is still a very powerful system)

Comments

  • edited August 3

    You're correct on all fronts: OnDownload should be called, and that is the correct fix.

    I'll apply this change to the next update, thanks for the breakdown.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.