GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Uppercase, Lowercase, Leading zeros, Reverse, Repeat, ASCII Keycode, etc.

HopscotchHopscotch Posts: 2,782Member, PRO
edited October 2015 in Working with GS (Mac)

Here are some useful LUA string and pattern matching hacks

that will make life easier:

Just add the function to the end of your attribute, joined by a ":"

.
Convert text to all uppercase:

self.Uppercase = self.Lowercase:upper()

.
Convert text to all lowercase:

self.Lowercase = self.Uppercase:lower()

.
Reverse a string of text:

self.Backwardtext = self.Forwardtext:reverse()

.
Repeat a string of text:

n is the number or repetitions of the whole text

self.Longwinded = self.Shortwinded:rep(n)

.
Get the ASCII Keycode of a character:

n is the character position in the string of text

self.AsciiNumber = self.Text:byte(n)

.
Get the character from its ASCII Keycode:

self.FormattingStyle = "%c"

self.TheCharacter = self.FormattingStyle:format(self.TheASCIIValue)

.
Leading and trailing zeros:

n = total number of characters
m = number of decimal places

for more formatting options search for printf and POSIX

self.FormattingStyle = "%0n.0mf"

self.FormattedNumber = self.FormattingStyle:format(self.NumberToBeFormatted)

Comments

Sign In or Register to comment.