Random text in dialogue box
Baccarda
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
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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.
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
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/
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.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
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)
thank you guys. it works like a charm.
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 ?
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
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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.
Any help on that guys?
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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.
How exactly i can set an attribute to current table row number ?
I suggest you watch some of the great videos on using tables. @Braydon_SFX has a few I think.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Thanks, @Armelline . @janis.piziks@gmail.com , I have a bunch of table videos located here in my community tutorial thread.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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.
@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.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page