Get seperate character/number count in text string [A-Z][0-9]

Hi all

I am trying to get a findtext to return a character count between [A-Z] and another for [0-9).

The task I am working on is to place an actor as a cursor on a text input field as part of a high score table.

Because the width of A-Z and 0-9 are different, I need to calculate the cursor position.x on a calculation on how many alphabetical and numberic values are contained in the text.

I know you can append lua to the end of a statement like :upper() but I cant seem to get a letter count of a string returned.

Any advanced GS people out there who would be able to help?

Looking for something like: change attribute self.lettercount = textfile(self.name,"%d",1) BUT need to place %d with something that returns the occurance count greater than 1 and not just 1.

If player is called "PLAYER 123" then I need self.lettercount = 6 and self.numbercount = 3

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited September 2020

    Have you tried using a monospaced font and textLength(game.textInput)?

    If you need to separate out the letters from the numbers, I guess you'd have to loop over the text string and check each letter using textSubStr(). I take it that's what this is about: https://forums.gamesalad.com/discussion/98103/substr-bug-in-loop-behaviour.

  • Chris FitsimonsChris Fitsimons Member Posts: 135

    Hi. In the end I looped with substr 👍

    i set char pixel width per char a-z and smaller for the numbers to match the font used. Almost perfect.

Sign In or Register to comment.