Uppercase, Lowercase, Leading zeros, Reverse, Repeat, ASCII Keycode, etc.
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
Great stuff Hopscotch, thanks for sharing this.
Fantastic tip!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Holy moly! I knew these existed in LUA (I've taken a few courses), but didn't even think that any of these would work in GameSalad! I particularly like the ":reverse()" hack - it removes the need for one of my old methods which included a loop to go through each character and write it to a new attribute. Crazy!
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Hey! That was fun!
Cool!
Very very cool... And big huzzah for reverse
Nice!
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Thanks for the comments everyone!
I added the counterpart to byte(), namely returning the character of a given ASCII value.
Strangely the usual char() does not work in GS, but a printf format works just as well.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Attached is a project showing the above functions in action.
This is in response to the suggestion from @Nabbo (ReflectiveByte) to use Custom Fonts for Health Bars: http://forums.gamesalad.com/discussion/comment/588551/#Comment_588551
The project does not include appropriate fonts for the Health Bars.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch
@RowdyPants
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com