Forum rules - please read before posting.

Syncronize GetSpriteDirection string to Global variable

Hi all,
I tryied to follow the manual and the Variable Linking Example but I cannot understand how to convert the sprite direction string from a custom script to a global variable in AC.
My script:

public string currentDir;

void Update()
{
    string currentDir = AC.KickStarter.player.GetSpriteDirection();

I have a Global Variable set as String with ID token 32... how can I make it change relying on currentDir?

Thanks for any help.

Comments

  • Are you trying to transfer the sprite direction to the variable, or use the variable to control the direction?

    If you're just trying to update the variable, you can do so without "linking" and just add the following to your Update function:

    AC.GlobalVariables.SetStringValue (32, currentDir);
    
  • Yep, just trying to update the variable.
    But...
    The AC string var 32 is still on "_R" and the integer 33 is still on "2", while "hello" on the console is writing hello a lot of times... so the script is working but is not refreshing the var value.
    Am I missing something? It is checking the main player movement, right?

    SCRIPT ActionCheckDirection.cs:

    public class ActionCheckDirection : MonoBehaviour
    {

    // Use this for initialization
    void Start()
    {
    
    }
    
    // Update is called once per frame
    void Update()
    {
    

    AC.GlobalVariables.SetStringValue(32, AC.KickStarter.player.GetSpriteDirection());
    AC.GlobalVariables.SetIntegerValue(33, AC.KickStarter.player.GetSpriteDirectionInt());
    Debug.Log("hello");
    }
    }

    Thanks

  • It is checking the main player movement, right?

    Should be - alter your Debug.Log statement to check:

    Debug.Log (AC.KickStarter.player.GetSpriteDirection ());
    

    Make sure that you revert your variable's Link to property back to None.

  • edited May 2021

    Variable already reverted to None.
    With the Debug.Log as you wrote, I still have _R forever on the console, even if I press the down button (I have the Direct method).
    And my Player is tagged as Player... maybe the "Allow player switching" can cause this issue?

  • Does the character visibly change direction?

    The Player's tag isn't relevant in the latest release, but you can determine which character is actually being read with:

    Debug.Log ("Player: " + AC.KickStarter.player, AC.KickStarter.player);
    

    Clicking that message in the Console will "ping" the Player in the Hierarchy.

  • Ok, I have identified the issue and solved it, thanks!
    But there's a way to write on the string all the current movement?
    Like "Walk_R" and not only "_R"? Because I need to know if it's running or walking.

  • public string GetAnimPrefix ()
    {
        switch (KickStarter.player.charState)
        {
            default:
            case CharState.Idle:
            case CharState.Decelerate:
                return KickStarter.player.idleAnimSprite;
    
            case CharState.Move:
                if (KickStarter.player.isRunning)
                {
                    return KickStarter.player.runAnimSprite;
                }
                return KickStarter.player.walkAnimSprite;
        }
    }
    
  • edited May 2021

    Many THANKS! It works perfect! :smiley:

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.