Happy Holidays Gift -- Free Text Manipulation Examples

RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
edited December 2014 in Working with GS (Mac)

Hope everyone is enjoying the season!

This little gift shows examples of how to manipulate text to accomplish various tasks, including;

  • Display system clock in text
  • Basic word search
  • Display text length
  • Repeat text
  • Replace a word
  • Replace all occurrences of a word
  • Get a substring of the text
  • Find the number of words in a paragraph
  • Find the number if items in a comma separated list
  • Find the number of lines (or number of paragraphs) of a document
  • Find the nth word in a sentence or paragraph
  • Replace the nth word in a sentence or paragraph with another word

Well.... you get the idea.
http://www.mediafire.com/download/lliozwj18h8x563/Text_Manipulation_Examples.zip

Happy Holidays!
RThurman

Comments

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Cool-e-o!!! Will be checking it out!!!

    Thanks and Merry Christmas!!!

  • Ed_PerkinEd_Perkin Midlands,UKMember Posts: 346

    Thank you , Merry Christmas ! :D

  • zweg25zweg25 Member Posts: 738

    Thanks! Happy holidays!

  • kirafukirafu Member, PRO Posts: 314

    Thank you and Merry Christmas !

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @KillerPenguinStudios‌, @Ed_Perkin‌, @zweg25‌, @kirafu‌, @Hopscotch‌
    You are very welcome!

    Happy Holidays!

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @jamie_c‌, @GSAnimator‌ -- You are welcome. Glad it will be useful to you.

    Happy New Year!

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    Excellent gift, very kind of you, sir!

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    @RThurman - hey, RT, you must have read my mind - I'm needing to know how many lines of type there are, and was going to post the question. Excellent stuff, and it deserves an "Awesome" :smile: Thanks v.m.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2014

    Ah, spoke too soon... I need to find the amount of lines as the words are being typed into a text field (Text Display actor); i.e register a new line when the text wraps to the next line.... I don't think that's possible though...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2014

    @gyroscope If you knew the font kerning and size (which you set, obviously), you could calculate how many characters would fit on one line of an actor with a certain width. With a non-fixed width font, you'd need to use an average number of characters so it wouldn't be perfect (e.g. "AAAAA is much narrower than WWWWW"). Then you could use textLength() and divide by the number of characters per line:

    ceil(textLength(game.text/game.AverageCharactersPerLine))

    Note: you're not so much calculating the average as just determining it with trial and error. Type out a line of characters as wide as the actor that are all 'I's and then one that is all 'W's and take the average.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2014

    @tatiang Good thinking, Tatian - though was hoping there would be a less laborious method!

    Still there''s the problem of finding out when a word wraps, how many letters in the wrapped word there is - so to carry on to get the width of the next line ... if you see what I'm saying...

    Not sure that'll be possible within the text limitations of GSC but I'm going to keep on badgering the problem to see if there's a solution...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2015

    @tatiang I think i've worked it out, based on your mathematical solution (i.e registering widths of each letter as it's typed then discovering which word wraps). Thanks. (Still got to put it into practice tho')... :smile:

    Edit: I'm now going to use Courier New, which is monospaced (and looks better than American Typewriter too) - so should be more straightforward now. :D

    •• BUMP ••

    @RThurman said:
    Hope everyone is enjoying the season!

    This little gift shows examples of how to manipulate text to accomplish various tasks, including;

    • Display system clock in text
    • Basic word search
    • Display text length
    • Repeat text
    • Replace a word
    • Replace all occurrences of a word
    • Get a substring of the text
    • Find the number of words in a paragraph
    • Find the number if items in a comma separated list
    • Find the number of lines (or number of paragraphs) of a document
    • Find the nth word in a sentence or paragraph
    • Replace the nth word in a sentence or paragraph with another word

    Well.... you get the idea.
    http://www.mediafire.com/download/lliozwj18h8x563/Text_Manipulation_Examples.zip

    Happy Holidays!
    RThurman

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited January 2015

    @Braydon_SFX‌ -- you are welcome!
    @gyroscope -- yes.. it won't work for that. But I bet you figure it out!
    @tatiang‌ -- good idea! I expect to see a demo soon!

    Happy New Year!

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2015

    @RThurman said:
    gyroscope -- yes.. it won't work for that. But I bet you figure it out!

    I have! Now i'm using Courier New, being a fixed width font, it's been relatively painless. So I now have letter count each/per line, word count, last actual word, and last actual word letter count -even when a word wraps to a new line, or a new para is made with Return. All good!

    i'm enjoying making this app so much I think I'll move it to the top of my list and publish it straight after Neko Montaaju and Sort 'Em. :) (For interest, and anyone else's too, I'll reveal what this app is about later on in Jan., when I've registered the name and got it looking a bit better).

    Happy New Year to you too. :smile:

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Alright!! The new year is already off to an excellent start for you!

  • slinky1988slinky1988 Member, PRO Posts: 89

    @RThurman

    Hiya! Thanks for posting this, its been a major help for a project I'm working on.

    I seemed to encounter a problem and was wondering if you could help me solve it. I have followed your example and configured it to delete the last letter of a text string which works perfectly fine however as soon as I input a 'space' to from a sentence I can no longer delete the last character. Is it possible to delete this or work around it in some way?

    Thanks again!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Are you using something like this?

    Change Attribute: self.myChangedString To: textSubStr(self.myText,1,textLength(self.myText )-1)

  • slinky1988slinky1988 Member, PRO Posts: 89

    @RThurman yes that is the expression I am using. Is it wrong? :s

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    That expression should work.
    ...
    I just tested it and it works fine. It eats the 'space' character like candy.

    Not sure why its not working for you.

  • slinky1988slinky1988 Member, PRO Posts: 89

    @RThurman

    Thanks for trying to help me figure this out. The code is configured in the same context as you've given, the only differences is that I'm not using a 'self' attribute but rather a global one since there are other actors that will be referencing the text string to words in a table.

    I had a issue before where my text string was not reading what was in the tables correctly because in the tables I had written sentences using the original space key that people would normally use on their keyboard, but on the keyboard I manually created within the project I had used the 'alt+space' to separate the words as I couldn't just use the standard space in the expression editor...therefore the spaces weren't the same and could not read each other. Could that be the issue? How are you separating your words?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Hmm.... I am not sure what the problem might be. It seems to me that it shouldn't matter what the character is. Alt-space is just as much of a text character as any other one.

    Perhaps you could create a small GameSalad file that demonstrates the same problem/issue and send it to me. I'll take a look and see if I can find a fix for this odd behavior.

  • slinky1988slinky1988 Member, PRO Posts: 89

    @RThurman
    Ok thanks I appreciate it.

    So the attached file is taken from my actual project, I just took off all the HUDS and removed un-needed rules and attributes for your convenience.

    It's not a major issue as alternatively I could just make the delete button clear the entire text string but that just wouldn't feel right in terms of UI designing. I thought the solution would be quite straight forward or that my code was wrong hence why I got in contact with you -so if you can't figure it out don't worry about it. :)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited May 2015

    @NASM -- using alt-space really does break it. The whole substring function goes to pot when it has an alt-space in the string.

    A quick workaround seems to get things backspacing again:

    1)Make an attribute (type = text) called mySpace.
    2)In the attribute browser (on the left pane), go ahead and set mySpace to one regular space (from the spacebar)
    3)In the spacebar actor, concatenate the text string to mySpace in the usual way:
    Change Attribute: game.TextstringAnswer To: game.TextstringAnswer..game.mySpace

  • slinky1988slinky1988 Member, PRO Posts: 89

    @RThurman

    lol every time I read your solutions in the forum the voice in my head always says 'dammit why didn't I think of that!'. Man - you're a great asset to this community, I hope you know that!

    Now I just got a tedious job of replacing all the alt spaces in my table to standard spaces so the text string can read of it again.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Thanks for the nod...
    always appreciated.

  • SocksSocks London, UK.Member Posts: 12,822

    @NASM said:
    lol every time I read your solutions in the forum the voice in my head always says 'dammit why didn't I think of that!'. Man - you're a great asset to this community, I hope you know that!

    Yep, I suspect he probably doesn't readily recognise it himself, but there's no getting away from it he's plainly just a little bit genius-y (I'm hoping that's a word :smile: ) I imagine if he shifted his focus away from GameSalad and to something else entirely he would similarly just hang around casually amazing bystanders !! :smile:

Sign In or Register to comment.