Forum rules - please read before posting.

Changing local variables doesn't work?

I'm working on a puzzle generator which is presently set up to save each 'step' of the puzzle's solution to local variables.  However, despite there being no errors when it attempts to do so, the changes it makes don't appear in AC's local variables.

What am I doing wrong here?  The script is attached to an OnStart cutscene GameObject and I'm calling it through a Send Message event in an ActionList.  Am I required to attach this script that's attempting to change local/global variables to AC's PersistentEngine object?

What's meant to happen is: 
1. the ActionList sends SetupPuzzle() to the OnStart cutscene gameobject (which the script is attached to)
2. SetupPuzzle fills local variables 9 through 15 with the string "Forward" (or if I uncommented the original code, either "Forward", "Left", or "Right")
3. SetupFlags chooses from a static list of possible solutions to whichever step of the player the puzzle is on.
4. That solution is sent to ChangeFlag, which either flips or doesn't flip the X of the spriterenderer that it's pointed to.

However, no flags change position and the local variables remain in their default null state.

The ActionList calling the method: image
My variable list: image

Comments

  • edited January 2017
    Well, how are you setting up variable 8? In the screenshot it shows 0, so the for loop may not even be running at all. When you get errors like these you must make sure to at least put some debug.logs after every condition, just to make sure how deep the program is getting, to find where it stops. If you aren't getting any compile warnings or runtime errors a condition is likely never getting met. Hence nothing seems to happen. If it was an issue with AC you'd most likely get errors or warning dialogues. So, first make sure the conditions are actually been met and the code is actually running. Also, you didn't show what the value of variable 2 is in your scene and it's the most important condition in the SetupPuzzle() method...
  • Nah, even with 8 stepsNeeded it doesn't set any strings.  Loop is running.
    No compile warnings/errors.

    Value of variable 2 is 'SnowPilgrim' at the time this is run.
  • edited January 2017
    Curiously, though, I have managed to make Unity consistently freeze now on my testing.

    Ah, I think that's being caused somehow by my trying to find the present scene.  Separate bug but figured I'd call it out while I continue to try and figure out why this isn't working.

    Present version of the script: https://hastebin.com/oxixogusid.cs
  • Well, after 3 days of trying to hack this thing apart I finally got it figured out.  No fault of the engine - I had a bad order of operations error sneakily hiding in my actionlist, an accidental duplicate object calling the same script, and a != needing to be ==.  All up and running now.

    This thread can be closed!
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.