Page 1 of 1
HELP WITH TIMER IN DIFERENT CARDS
Posted: Sat Apr 04, 2015 3:37 pm
by Jesus.tj
Hello Community LiveCode. I'm making a program that simulates the administration of a Billiards. This program has a main interface where you can choose the table you want to go. Everything was going well until I encountered the problem that the timer on each card that I do not continuous if I go to another card. How I can do to make skillful timer is still running even though it is not within my check card without any problems?
My code is as follows:
Code: Select all
global Segundos
global Minutos
On MouseUp
IniciaSegundos
end MouseUp
on IniciaSegundos
put empty into fld "Segundos"
put 0 into Segundos
put 0 into Minutos
ActualizaSegundos
end IniciaSegundos
on ActualizaSegundos
if Segundos >= 0 and Segundos <60 then
put Segundos into field "Segundos"
put Segundos + 1 into Segundos
send "ActualizaSegundos" to me in 1 second
end if
if Segundos =60 then
add 1 to Minutos
put Minutos into fld "Minutos"
put 0 into Segundos
end if
end ActualizaSegundos
Please, I need your Help. THANKS!
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Sat Apr 04, 2015 3:46 pm
by Klaus
Hola Jesus,
1. welcome to the forum!
2. Not sure I understand your problem but you should add a descriptor to your field,
so it can be filled with the timer even if you are on anohter card:
Code: Select all
...
on IniciaSegundos
put empty into fld "Segundos" OF CD "the card with field Segundos on it"
...
on ActualizaSegundos
if Segundos >= 0 and Segundos <60 then
put Segundos into field "Segundos" OF CD "the card with field Segundos on it"
...
And maybe you should move the handlers "IniciaSegundos" and "ActualizaSegundos" to the stack script.
Best
Klaus
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Sat Apr 04, 2015 4:08 pm
by Jesus.tj
Thank you very much for answering Klaus.
Okay! I understand how it works ... And it seems perfect ... But I find another problem ... In the main menu administration, whenever you add a card table is added as well, and therefore everything should work just .. .. what I want to know in this logic is. How I can make each timer of each card works well? What you tell me works perfectly, but one card is defined .. The problem is that the cards can be endless ....
It's worth, WHENEVER YOU WANT TO CREATE A CARD, HE CREATED THE FIRST CLONE, MEANING YOU ALL CARDS HAVE THE SAME COMPONENTS, SUCH "FLD SECONDS", "FLD MINUTES" ...
It occurs to me is add the code you provided me in real time every time it runs. But you would have to add both the stack and the card to be cloning-creating -... WHAT DO YOU THINK? DO ANY OTHER OPTION?
THANK YOU!
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Sat Apr 04, 2015 4:13 pm
by Klaus
Hola Jesus,
so you want to have the SAME timer (field "Segundos" and "Minudos") on each (new) card?
Hint: Here some great learning resources for the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Sun Apr 05, 2015 12:14 am
by Newbie4
I am also not sure what you are asking.
A) If you want just one timer that runs continuously no matter what card that you are on then put your original code on the stack script. Then on each card in its "openCard" script put
Code: Select all
global Segundos
global Minutos
put Segundos into field "Segundos"
put Minutos into fld "Minutos"
So every card should have the current time when it opens and keep updating it. Since you have the timer update code on the stack script, it should continue running no matter what card you are on.
B) If you want each card to start and maintain its own timer, the your original code goes on the card script. If you go to another card, you have to stop that timer or you will get an error on the next card especially if it does not have the same fields
Does this make sense and help?
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Mon Apr 06, 2015 5:05 pm
by Jesus.tj
Thank you very much to both of you for answering! = D
And I've managed to solve the problem. It was relatively simple, each card should have their own variables and defined events from the stack. In this logic, I will introduce myself a little problem. At the time of each card cloning and variables, etc .. Within the stack I need to put these values into the new card such believe, then, every time I make a creation also add code to the stack, something like this:
Code: Select all
put "on IniciaSegundosMesa...."
put "put Minutos into fld 'Minutos'"
put "put Horas into fld 'Horas'"
put "ActualizaSegundosMesa"
put .........................
put s3 into FINAL2
............
answer final2
and then the script will be that contain the stack
The rest of the code if marketed correctly. But I find the main problem in that when you put "put ...." profit not put quotation marks text field ....
How I can do to add, I tried and I do not manage to do, so it is
Code: Select all
"put Segundos into fld "Minutos" ".....
,and that is the right way??....
Thank you and greet you, and I hope that those who have the same problem I have helped with this little solution.
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Mon Apr 06, 2015 5:13 pm
by dunbarx
Hi.
If I understand your question, know that quotes are also constants. Try this:
answer "test" & return & quote & "test" & quote
Craig Newman
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Mon Apr 06, 2015 5:18 pm
by Jesus.tj
Re: HELP WITH TIMER IN DIFERENT CARDS
Posted: Tue Apr 07, 2015 12:43 pm
by Klaus
Hola Jesus,
sound like you make this unneccessarily complicated!?
No need for cloning/copying stuff and create scripts on the fly, which is a bad idea anyway.
You can have a the SAME fields (segundos/minudos) fields on every card when you GROUP these two fields!
Do something like this:
1. Select these two fields on the first card they appear. Delete all duplicates from other cards first.
2. GROUP (command-G or use the menu OBJECT -> Group Selected)
3. Give that new group a name, maybe TIMER.
4. No go to every card you want to show the timer and use menu OBJECT -> Place group -> TIMER (or whatever you named that group)
5. Move these handler to the STACK script:
Code: Select all
global Segundos
global Minutos
on IniciaSegundos
put empty into fld "Segundos" OF BG "TIMER"
put 0 into Segundos
put 0 into Minutos
ActualizaSegundos
end IniciaSegundos
on ActualizaSegundos
if Segundos >= 0 and Segundos <60 then
put Segundos into field "Segundos" OF BG "TIMER"
put Segundos + 1 into Segundos
send "ActualizaSegundos" to me in 1 second
end if
if Segundos =60 then
add 1 to Minutos
put Minutos into fld "Minutos" OF BG "TIMER"
put 0 into Segundos
end if
end ActualizaSegundos
This way we can have the timer running all the time and the fields get filled with the correct value,
even if that goup is NOT part of the current card!
Hint:
Since this way we actually have the SAME two fields on the cards, their location will always be the same
where you last set it! If neccessary, you can set the location of grp "timer" "on preopenstack".
Best
Klaus