Random text in dialogue box

BaccardaBaccarda Member Posts: 122

Hello everyone

Is it possible to make a dialogue box which shows random text after an action? How much text i could store in the app and would it affect performance and app size ?

Thanks in advance :)

Comments

  • ArmellineArmelline Member, PRO Posts: 5,354
    edited June 2016

    Yes, this could be done easily. Put the text in a table and pick a random row. You could store thousands of lines of text without it affecting performance or increasing the app size too much.

  • BaccardaBaccarda Member Posts: 122

    @Armelline said:
    Yes, this could be done easily. Put the text in a table and pick a random row. You could store thousands of lines of text without it affecting performance or increasing the app size too much.

    Is there any tutorial on this? I have not worked with tables and probably there should be an action formula which triggers the random text. :D

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited June 2016

    Display Text: tableCellValue(TableName, random(1, tableRowCount(TableName)), 1)

    If you want it to change each time after a particular action then put the tableCellValue code above into an attribute and then display that i.e.

    ChangeAttribute: self.randomText = tableCellValue(TableName, random(1, tableRowCount(TableName)), 1)
    Diplay Text: self.randomText

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited June 2016

    And take a look at these pages if you've not worked with tables before

    http://help.gamesalad.com/gamesalad-cookbook/2-making-it-better/2-06-using-tables/
    http://help.gamesalad.com/gamesalad-cookbook/2-making-it-better/2-07-writing-to-tables/

    And there's a brief description of each table function on this page. Search for functions and then scroll down to the table ones:

    http://help.gamesalad.com/gamesalad-cookbook/1-getting-started/1-11-glossary/

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Below is a tutorial I did a while ago about creating RPG style text conversations. It's not random, but it might help you understand the table part.

  • BaccardaBaccarda Member Posts: 122

    @KevinCross said:
    Display Text: tableCellValue(TableName, random(1, tableRowCount(TableName)), 1)

    If you want it to change each time after a particular action then put the tableCellValue code above into an attribute and then display that i.e.

    ChangeAttribute: self.randomText = tableCellValue(TableName, random(1, tableRowCount(TableName)), 1)
    Diplay Text: self.randomText

    I would like to store many units of text in a database and each time i touch the box it changes the text to a random one.

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited June 2016

    @janis.piziks@gmail.com said:
    I would like to store many units of text in a database and each time i touch the box it changes the text to a random one.

    It's the same code

    Code on your actor:
    ..Display Text: self.randomText
    ..Rule: When Touch Is Pressed
    ....Change Attribute: self.randomText = tableCellValue(TableName, random(1, tableRowCount(TableName)), 1)

  • BaccardaBaccarda Member Posts: 122

    thank you guys. it works like a charm.

  • BaccardaBaccarda Member Posts: 122

    Oh, just one more thing.
    What if i would like just to show the title of text and after clicking on it show the rest of the text?
    Could it work using the same function ?

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    You would need to store the random number in an attribute because each time you call that code it picks a different random number so the title and the main text would be different each time and won't match up.

    Something like this:

    Code On Actor:
    ..Display Text: self.randomText
    ..Rule: When Touch Is Pressed And self.pressedCount = 0
    ....Change Attribute: self.randomRow = random(1, tableRowCount(TableName))
    ....Change Attribute: self.randomText = tableCellValue(TableName, self.randomRow, 1)
    ....Change Attribute: self.pressedCount = 1

    ..Rule: When Touch Is Pressed And self.pressedCount = 1
    ....Change Attribute: self.randomText = tableCellValue(TableName, self.randomRow, 2)
    ....Change Attribute: self.pressedCount = 0

    Something along those lines, you can probably nest the rules.

    This is based on your table containing the title of the text in column 1 and the main body/description text being in column 2

  • ArmellineArmelline Member, PRO Posts: 5,354

    @janis.piziks@gmail.com said:
    Oh, just one more thing.
    What if i would like just to show the title of text and after clicking on it show the rest of the text?
    Could it work using the same function ?

    Yes. Just put the title in one column, the text in another. Show the title, and when they click, display the next column containing the text.

  • BaccardaBaccarda Member Posts: 122

    Basically i need to have 2 actors
    1. The text box
    2. Generate random text button

    I need to change the title in the text box when the button is pressed and change the text to a full text when the title text is touched.

    Im now trying to stick it all together. :D

  • BaccardaBaccarda Member Posts: 122

    Any help on that guys? :D

  • ArmellineArmelline Member, PRO Posts: 5,354

    @janis.piziks@gmail.com said:
    Any help on that guys? :D

    Doing what you just said should work. Though it could potentially be done with 1 actor depending on exactly what you're trying to achieve.

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    @janis.piziks@gmail.com said:
    Basically i need to have 2 actors
    1. The text box
    2. Generate random text button

    I need to change the title in the text box when the button is pressed and change the text to a full text when the title text is touched.

    Im now trying to stick it all together. :D

    For number 1 have an actor that has

    Display Text: game.randomText

    For number 2 do roughly what I said in this comment: http://forums.gamesalad.com/discussion/comment/582654/#Comment_582654

    But remove the Display Text from the code and use a game attribute for randomText instead of a self one so that actor 1 can access it.

  • BaccardaBaccarda Member Posts: 122

    How exactly i can set an attribute to current table row number ?

  • ArmellineArmelline Member, PRO Posts: 5,354

    I suggest you watch some of the great videos on using tables. @Braydon_SFX has a few I think.

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

    Thanks, @Armelline . @janis.piziks@gmail.com , I have a bunch of table videos located here in my community tutorial thread.

  • BaccardaBaccarda Member Posts: 122

    Thank you guys for the tutorials but i still cant find a way, to display the text which is located next to titles column. I can only make it to show random text from side column but not the exact row as title.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    @janis.piziks@gmail.com, If you want to show the actual title you enter for a row or column I don't you think can pull that directly out of the table. You'd need to add the title as an element to the table (besides in the title location) and then pull it from there.

    For example if you had a row titled 'row 1' you could make the first column of that tables value 'row 1' and pull the title/value from there.

Sign In or Register to comment.