1 (edited by FreedTerror 2021-03-25 20:46:45)

Topic: [Solved] Need help with a moveinfo script

I'm In need of some help with a moveinfo script.

The goal of this script is to check if a move that's being used is one of the moves on the script, then do a thing.

The issue I'm having is the script only seems to work with the Element 0 properly.
https://i.imgur.com/LBpYH4x.png

When a move in any of the other Element's is used it executes the if and the else if

  public void CheckIfMoveIsEnhanced()
    {
        foreach (MoveInfo move in enhancedMoves)
        {
            if (cScript.currentMove.moveName == move.moveName)
            {
                script.enabled = true;
                Debug.Log("CheckIfMoveIsEnhanced");
                break;
            }
            else if (cScript.currentMove.moveName != move.moveName)
            {
                script.enabled = false;
                Debug.Log("CheckIfMoveIsNonEnhanced");
            }
        }
    }

Any help or a better way to do this would be greatly appreciated smile

I used some of @MrPonton's AlternatePalettes code from this thread: http://www.ufe3d.com/forum/viewtopic.php?id=2469

Full code of script I'm using:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UFE3D;

public class EnhancedMoves : MonoBehaviour
{
    public List<MoveInfo> enhancedMoves;
    public MonoBehaviour script;

    private ControlsScript cScript;

    // Start is called before the first frame update
    void Start()
    {
        cScript = gameObject.GetComponentInParent<ControlsScript>();
    }

    // Update is called once per frame
    void Update()
    {
        if (UFE.p1ControlsScript != null && UFE.p2ControlsScript != null && cScript.currentMove != null)
        {
            CheckIfMoveIsEnhanced();
            Debug.Log("if");
        }
        else
        {
            CheckIfNotPreformingMove();
            Debug.Log("else");
        }
    }

    public void CheckIfMoveIsEnhanced()
    {
        foreach (MoveInfo move in enhancedMoves)
        {
            if (cScript.currentMove.moveName == move.moveName)
            {
                script.enabled = true;
                Debug.Log("CheckIfMoveIsEnhanced");
                break;
            }
            else if (cScript.currentMove.moveName != move.moveName)
            {
                script.enabled = false;
                Debug.Log("CheckIfMoveIsNonEnhanced");
            }
        }
    }

    public void CheckIfNotPreformingMove()
    {
        script.enabled = false;
        Debug.Log("CheckIfNotPreformingMove");
    }
}

Share

Thumbs up Thumbs down

2 (edited by MrPonton 2021-03-24 19:42:09)

Re: [Solved] Need help with a moveinfo script

I'm unfamiliar with the use of

script.enabled = true;

So I'd reckon that the way you are using it might be an issue.

Also, a suggestion on cleaning up your code might help in debugging:

        foreach (MoveInfo move in enhancedMoves)
        {
            if (cScript.currentMove.moveName == move.moveName)
            {
                script.enabled = true;
                Debug.Log("CheckIfMoveIsEnhanced");
                break;
            }

            script.enabled = false;
            Debug.Log("CheckIfMoveIsNonEnhanced");
        }

That yields the same result as your previous if/else statement in the loop. In this case I can see a logical pathway that could be causing issues.

For example, let's say that you have a list of two moves in the enhancedMoves array [eMove1 and eMove2].

Now, as long as you're performing eMove1 you shouldn't have an issue.
Where you would have an issue is in performing eMove2.
My understanding occurs because of the following reasons:
    (1) The CheckIfMoveIsEnhanced() method is being called every frame.
    (2) On the first Update() tick (frame) that the eMove2 is being performed, it's going to properly register the script.enabled.
    (3) On every proceeding frame that eMove2 is being performed, it's going to hit `script.enabled = false;` because eMove1 which is checked first is not being performed. This will (I presume) end any functionality of the script being disabled. Then on that same frame it will enable it again but because it was previously disabled it will run the Start() and Awake() functions I believe.

So that's some things I see as problematic code in your current script. Sorry I can't be of much more help at this time.

Share

Thumbs up +2 Thumbs down

3 (edited by FreedTerror 2021-03-25 20:56:57)

Re: [Solved] Need help with a moveinfo script

I ended up solving the issue I was having.

From this thread: http://www.ufe3d.com/forum/viewtopic.php?id=2469 I basically just copied the way @MrPonton did
CheckIfMoveIsEx();
CheckIfMoveIsSuper();
HideAllGhosts();

I'm using this script to enable and disable a component that does a visual effect to the character.

Put the moves you want to trigger the visual effect in enhanced moves
Put the moves you don't want to trigger the visual effect in nonenhanced moves
Put the script you want to enable and disable in Monobehavior script

Here's the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UFE3D;

public class EnhancedMoves : MonoBehaviour
{
    public List<MoveInfo> enhancedMoves;
    public List<MoveInfo> nonenhancedMoves;
    public MonoBehaviour script;

    private ControlsScript cScript;

    // Start is called before the first frame update
    void Start()
    {
        cScript = gameObject.GetComponentInParent<ControlsScript>();
    }

    // Update is called once per frame
    void Update()
    {
        if (UFE.p1ControlsScript != null && UFE.p2ControlsScript != null && cScript.currentMove != null)
        {
            CheckIfMoveIsEnhanced();
            CheckIfMoveIsNonEnhanced();
            //Debug.Log("if");
        }
        else
        {
            HideEffect();
            //Debug.Log("else");
        }
    }

    public void HideEffect()
    {
        script.enabled = false;
        //Debug.Log("HideEffect");
    }

    public void CheckIfMoveIsEnhanced()
    {
        foreach (MoveInfo move in enhancedMoves)
        {
            if (cScript.currentMove.moveName == move.moveName)
            {
                script.enabled = true;
                //Debug.Log("CheckIfMoveIsEnhanced");
                break;
            }
        }
    }

    public void CheckIfMoveIsNonEnhanced()
    {
        foreach (MoveInfo move in nonenhancedMoves)
        {
            if (cScript.currentMove.moveName == move.moveName)
            {
                script.enabled = false;
                //Debug.Log("CheckIfMoveIsNonEnhanced");
                break;
            }
        }
    }
}

Share

Thumbs up +1 Thumbs down