Forum rules - please read before posting.

Action list action to check variable length

I need to check if keypad variable is already in full length and I would like to have a check as an AL action. I couldn't find an example close enough to get me started.

Comments

  • edited April 2022

    As in, how many characters in a string?

    If you're dealing with a keypad puzzle, and each digit is a separate digit, see the "Combination lock" scene in the "Puzzle template: Simple examples" package on the Downloads page.

    This Action will let you compare the length of a string, and supports variable tokens:

    using UnityEngine;
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCheckStringLength : ActionCheck
        {
    
            public override ActionCategory Category { get { return ActionCategory.Custom; }}
            public override string Title { get { return "Check string length"; }}
    
    
            public string stringToCheck;
            public int lengthToCheck = 10;
    
    
            public override bool CheckCondition ()
            {
                string runtimeString = AdvGame.ConvertTokens (stringToCheck);
                return runtimeString.Length == lengthToCheck;
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                stringToCheck = UnityEditor.EditorGUILayout.TextField ("String:", stringToCheck);
                lengthToCheck = UnityEditor.EditorGUILayout.IntField ("Length:", lengthToCheck);
            }
    
            #endif
    
        }
    
    }
    
  • There seems to be something wrong, I only get an empty AL action with it.

  • Typo. Try it now.

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.