Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Parse Number#

Strings / Parse Number

  • Can Read

  • Cannot Write

Description#

Reads a text as a number. Returns the fallback value when the text cannot be read

Parameters#

Name Description
Text The text that is interpreted as a number
Fallback The value returned when the text is not a valid number

Code#

using System;
using System.Globalization;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Parse Number")]
    [Category("Strings/Parse Number")]

    [Description("Reads a text as a number. Returns the fallback value when the text cannot be read")]
    [Image(typeof(IconNumber), ColorTheme.Type.Yellow, typeof(BadgeString))]

    [Parameter("Text", "The text that is interpreted as a number")]
    [Parameter("Fallback", "The value returned when the text is not a valid number")]

    [Keywords("String", "Convert", "Cast", "To Number", "Float", "Integer", "Decimal")]

    [Serializable]
    public class TypeNumberStringParse : TypeNumber
    {
        [SerializeField] private GetString m_Text = new GetString();
        [SerializeField] private GetNumber m_Fallback = new GetNumber(0f);

        public override double GetPreview(GameObject source) => Parse(
            this.m_Text.GetPreview(source),
            this.m_Fallback.GetPreview(source)
        );

        public override double Get(Args args) => Parse(
            this.m_Text.Get(args),
            this.m_Fallback.Get(args)
        );

        private static double Parse(string text, double fallback)
        {
            if (string.IsNullOrEmpty(text)) return fallback;

            return double.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out double value)
                ? value
                : fallback;
        }

        public override string ToString()
        {
            return $"Number of {this.m_Text}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.