View Full Version : Random Messages
evoman
08-16-2004, 09:41 PM
I am trying to figure out how to have a different message pop up on the screen every time a users clicks the same button. Can this be done? if so How :huh
Thanks
Intrigued
08-16-2004, 10:07 PM
I hope this helps.
Note: Code is in only two (2) areas:
On Preload (Page1)
and...
On Click (Button1)
Sincerely,
Intrigued
08-16-2004, 10:17 PM
Here is the same sort of idea but now we are using timed messages (2000ms == 2 seconds) and also now the tips continue to rotate indefinitely with each click (well, through all three of them anyway). Thus, not stopping at the third tip anymore! Great for application startup tips, for example.
Now I use just can click the Click for Tip! Button Object. Just a tad more user friendly is one way to see it.
Sincerely,
TJ_Tigger
08-17-2004, 09:02 AM
Here is anothe way to do it from a file. The file contains a quote per line that is read into a table. The table is then used to display the quotes, initially it is a random quote that is displayed. There are two navigation buttons, one for the next quote, and one for a random quote.
Intrigued
08-17-2004, 09:12 AM
Here is anothe way to do it from a file. The file contains a quote per line that is read into a table. The table is then used to display the quotes, initially it is a random quote that is displayed. There are two navigation buttons, one for the next quote, and one for a random quote.
And finally we could rap it all up in a SQLite Plugin's database for ultimate manipulation purposes.
So that would give us three ways of handling it.
1. Random message 'hard coded' into the Action's editor code (my offering)
2. Random messages in a 'flat file' (Tigg's offering)
3. Random messages in a SQLite database (to be offered? (grin))
Sincerely,
MIchaelD
08-17-2004, 10:53 AM
Here is another way to do it from a file. The file contains a quote per line that is read into a table. The table is then used to display the quotes, initially it is a random quote that is displayed. There are two navigation buttons, one for the next quote, and one for a random quote.
I'm a beginner, so please excuse me if this is a dumb question. This is exactly what I came to the forum looking for this morning. However, I don't know how to make a table, add the quotes and how to use it.
Can you please advise.
Many Thanks,
MichaelD
TJ_Tigger
08-17-2004, 12:47 PM
I'm a beginner, so please excuse me if this is a dumb question. This is exactly what I came to the forum looking for this morning. However, I don't know how to make a table, add the quotes and how to use it.
Can you please advise.
Many Thanks,
MichaelD
Here is a great place to start learning about tables. The following is a copy of the helpfile for AMS5.
Tables(arrays) (http://www.indigorose.com/webhelp/ams50/Scripting_Guide/Tables_(Arrays).htm#_Toc47928334)
The above link will tell you a lot about tables. Also if you search the forums, and look in the Examples forum, you will find a lot of entried about tables, how to make them and use them.
In the above example, all I did was create a text file that contained one quote per line. I then use the action TextFile.ReadToTable (http://www.indigorose.com/webhelp/ams50/Program_Reference/Actions/TextFile.ReadToTable.htm) which reads the contents of a text file into a table. Each line becomes an indexed entry in the table you specify.
Example:
--This code will read the specified file into a table called tblQuotes
tblQuotes = TextFile.ReadToTable("AutoPlay\\Docs\\quotes.txt");
I would also suggest looking at the for (http://www.indigorose.com/webhelp/ams50/Scripting_Guide/Tables_(Arrays).htm#_Toc47928338) control structure which can be used to traverse the contents of a table.
Example:
--This code will go through each entry in the table and display its contents in a dialog box.
for tableindex, tablevalue in tblQuotes do
Dialog.Message("Quote"..tableindex, tablevalue);
end
I hope this has been helpful.
Tigg
Intrigued
08-17-2004, 01:13 PM
TJ Tigg... I am impressed!
I took a couple minutes to look over the code base in that application you posted.
I know if I had posted a solution to the randomizing of the flat file it would have contained around twice as much code to accomplish such!
Thank you for taking the time to whip up that code chunk. It showed me another example on how to compact code.
If you do not mind me saying, you are the Tables Man as far as I am concerned! (grin)
Very Sincerely,
MIchaelD
08-17-2004, 02:19 PM
Here is a great place to start learning about tables. The following is a copy of the helpfile for AMS5.
Thank you TJ_Tigger. I very much appreciate the detailed answer and I'll be busy trying to figure it all out.
I know nothing about programming, but I was tickled by how simply you solved the original problem.
Best regards,
MichaelD.
TJ_Tigger
08-17-2004, 02:59 PM
Thanks guys, I appreciate the kind words.
MichaelD I am not a programmer either, just a Trainer making do with what I can. They people on the forums and at IR have been helpful in the past, just trying to help when and where I can.
If there are other questions I will try to help.
Tigg
MIchaelD
08-19-2004, 02:35 PM
which reads the contents of a text file into a table. Each line becomes an indexed entry in the table you specify.
Example:
--This code will read the specified file into a table called tblQuotes
tblQuotes = TextFile.ReadToTable("AutoPlay\\Docs\\quotes.txt");
I hope this has been helpful.
Tigg
Hello Again Tigg,
I followed all your suggestions and also printed out the "Tables" pages and the Scripting guide.
In trying to replicate your example project with a my own text file I now have;
1. A project with a button and a paragraph object.
2. My text file (1 quote per line, single spaced) in the Project "Docs" folder.
3. Copied and pasted the code from your "next quote" button to mine.
What I don't know is where to write the following script;
tblQuotes = TextFile.ReadToTable("AutoPlay\\Docs\\quotes.txt");
I don't know where it goes either, as I couldn't find it in your example.
I'm sure this is something that should be obvious to anyone with half a brain, so I apologise.
Thanks for your help.
Best Regards,
MichaelD
TJ_Tigger
08-19-2004, 04:18 PM
MichaelD,
There are various places you can put that code. I placed it on the [On Preload] event for the page that contains the quotes. You could also put it in the [On Startup] event for the project. Project -> Actions from the menu.
I hope this helps.
Tigg
MIchaelD
08-19-2004, 06:43 PM
MichaelD,
There are various places you can put that code. I placed it on the [On Preload] event for the page that contains the quotes. You could also put it in the [On Startup] event for the project. Project -> Actions from the menu.
I hope this helps.
Tigg
Thank you very much, Tigg!
Regards,
MichaelD.
TJ_Tigger
08-19-2004, 08:45 PM
no problemo
MIchaelD
08-20-2004, 08:44 AM
Hi Tigg,
I made changes in your code to account for the name of my text file and may have done it wrong. When I run it and click on the button I get the following;
"On Click, Line 1: attempt to perform arithmetic on global 's' (a nil value).
My text file is named "stop". Following are the changes I made to your code;
s = s + 1;
if s > Table.Count(tblstop) then
s = 1;
end
if String.Find(tblstop[s], String.Char(9), 1, false) then
quote = String.Replace(tblstop[s], String.Char(9), "\r\n", false)
Paragraph.SetText("Paragraph1", quote);
else
Paragraph.SetText("Paragraph1", tblstop[s]);
end
I added to Project 'on startup';
tblstop = TextFile.ReadToTable("AutoPlay\\Docs\\stop.txt");
as you suggested.
Thanks for your help.
Regards,
MichaelD
TJ_Tigger
08-20-2004, 09:21 AM
In the project startup put this line with your TextFile.ReadToTable action
s = 1;
The variable s does not have a value.
MIchaelD
08-20-2004, 09:05 PM
In the project startup put this line with your TextFile.ReadToTable action
s = 1;
The variable s does not have a value.
Thanks again Tigg, I'll do it.
Regards,
MichaelD
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.