Random Quotes / Need help with resetting once table deletes all rows
ctwllc
Member, PRO Posts: 19
So I followed this video tutorial from tshirtbooth
I've got this working great, but of course once it hits empty rows (which I have 110 rows and sometimes it does NOT go through all rows before going blank) it goes blank.
What I want to figure out is how to never go blank but just refresh/recycle/copy the table so it starts over from the beginning?
Answers
@ctwllc , by the sounds of it, you just want your app to endlessly display random quotes. So no specific levels with a set number of quotes/questions?
In this case,
Create a second Table, lets call it WorkingTable, with the same number and type of columns as the SourceTable.
Make a rule:
if tableRowCount(game.QuotesTable) <= 1
then Copy Table from SourceTable to WorkingTable
Now change your existing code to run against the WorkingTable.
This table will now get reduced to empty, then get filled again from the SourceTable.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch Sorry, but how would I create that rule, and where?
The other question I have is, if I have 110 rows and the code from that video is supposed to cycle through all 110 while removing one from the index until there are none left, how come I keep coming up short... for example I refreshed three times (because I'm still getting to the blanks)... I got 82, then 40, then 74... never the entire 110.
This is what I have (trying to do what you said... trying) in the actor that displays the quotes...
https://www.dropbox.com/s/sg5ifyd16xptcvm/Screenshot 2015-10-30 21.32.48.png?dl=0
And this is what I have on the actor that you press to change the quote...
https://www.dropbox.com/s/pmf44xo430pj7k1/Screenshot 2015-10-30 21.34.57.png?dl=0
@ctwllc the rule should be at the top, in the actor which cycles through the table.
Why you come up short I would not be able to tell without seeing your code. Something must be removing rows more than once per cycle. Can you post a screenshot of the code?
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch let me know if the screen captures I gave you above are enough or if you need more?
---- posted below for you too ----
This is what I have (trying to do what you said... trying) in the actor that displays the quotes...
https://www.dropbox.com/s/sg5ifyd16xptcvm/Screenshot 2015-10-30 21.32.48.png?dl=0
And this is what I have on the actor that you press to change the quote...
https://www.dropbox.com/s/pmf44xo430pj7k1/Screenshot 2015-10-30 21.34.57.png?dl=0
@Hopscotch actually, I can't figure out how to make the rule like you 'if tableRowCount(game.QuotesTable) <= 1'
@ctwllc , now I see why you end up short in some cases:
You get a random row number, and the display behavior shows what is current at that position.
Your touch rule just deletes the first row in the table, making rows shift up and a new quote display.
So, if you happen to be displaying the last row in the still partially full table, and then press touch, this first row gets deleted, the rest shifts up and the display text has nothing more to show, as the row it is trying to display is now past the end of the table.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
The whole thing is a single scene.
So I have an actor that displays the quote.
CHANGE ATTRIBUTE:
Change Attribute: 'self.Row' To: 'random(1, tableRowCount (game.quotes))'
DISPLAY TEXT:
Text: '(tableCellValue( game.quotes , self.Row ,1)'
And I have a button that changes the quote.
RULE:
'actor receives event' 'touch' is 'pressed'
ADD/REMOVE ROW:
Table: 'quotes'
Action: 'Remove Row' 'At Index' '1'
This happens by deleting 1 from index each time the button is pressed and a quote is shown.
@ctwllc , see my explanation above why this does not work.
Give me a few minutes, I will be back with a sample project.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
I thought it was something like this... and although it isn't 'right' if I could refresh (copy the quotes_backup over quotes_working) it wouldn't matter so much... I guess... but it still wouldn't be right. Can't wait to see your sample project... thanks so much BTW.
@Hopscotch I'm working on implementing this into my app, but I think I may be missing something...
also, is there any way to get the Display Text to be on a different actor?
Again, thanks so much.
@Hopscotch So, I got it working and it's amazing... works great.
But I still have the question I had before of can I target the quotes to show inside a different actor so I can size it and constrain it to the actor. This is what I really need to be able to do.
Also one last thing is how can I make it start off with a quote... right now you have to press the button once when it starts up to see a quote... could it just show a quote at start up then change with button click?
Thanks for all your help... you've been great!
@ctwllc, check the behaviors in the "Initialize" group. You may be missing those if there is no quote at start.
To move the display into a different actor, just chage the "current row" attribute to a game level attribute. Then you can call the display text from anywhere.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch So yes, I must be doing something slightly wrong because...
So basically I'm still trying to figure out why it's not copying the table when it goes blank.
@ctwllc I will be at this in a couple of hours and do a demo where the display is separate from the control behavior.
Or just compare my project carefully to yours, also note the "otherwise" section as noted in the project.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Not sure if you saw this, but I got it working now where the quote shows on load ( I was missing a ")" in the Group - Initialize Change Attribute.
So now the only issue is the looping...
HA!! @Hopscotch it was totally my fault... the 'Otherwise' in the last row was closed and so I totally missed it... added and now it's working FLAWLESSLY!!!
Thank you for all your help. If I can ever help out in any way I'd love to!!
Cheers,
~ Justin
Super @ctwllc
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com