Count up timer over multiple cards

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Count up timer over multiple cards

Post by CammyGray21 » Thu Jan 01, 2015 1:20 pm

Hi guys,

I have a timer in my game that I am trying to implement over multiple cards so that when the card switches it takes the time from the field previous and puts it into the next to continue (Or so in theory) this will then be placed into a leaderboard at the end of the game along with Name etc that you would normally find there. Just wondering if anyone could give me a kick start on how to get the timer to work over the cards and will see how it goes from there!

Cheers!

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Count up timer over multiple cards

Post by jmburnod » Thu Jan 01, 2015 4:17 pm

Hi,
You can make a group with your objects timer
This group should have "behave like background" option to true.
Then you can place this group in each cd.
When you create a new cd this group is automaticaly placed onto the new cd. :D
Best regards
Jean-Marc
https://alternatic.ch

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Re: Count up timer over multiple cards

Post by CammyGray21 » Thu Jan 01, 2015 5:34 pm

Hey thanks for the reply but it is more getting the time to carry over from one card to another that I am stuck on at the moment. So on card one when the timer starts, say it gets to 12 when the card switches 12 will be placed into the next timer and will continue to count up from there, continuing to take the number and place it into the next timer until the game completes therewith the time being placed into the leaderboard. Also on another note I am not an avid livecoder we were given a school project to complete livecode was our means of doing so. So not to sound needy but as much in depth help as possible would be appreciated.

Thanks!

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Count up timer over multiple cards

Post by Martin Koob » Thu Jan 01, 2015 6:30 pm

You can take advantage of script locals and the fact that references in the stack script to objects will apply to the objects of the current card.

On each card put a field named "timeDisplay".
On at least one card put a button "start Timer" that calls the command 'startTimer'
On at least one card put a button 'stop Timer' that calls the command 'stopTimer'

in your stack script put the following:

Code: Select all


local sStartTime, sTimerOn

on startTimer
   put true into sTimerOn
   put the seconds into sStartTime
   send "incrementTime" to me in 1 second
end startTimer

on incrementTime
   put the seconds - sStartTime into field "timeDisplay"
   if sTimerOn is true then
      send "incrementTime" to me in 1 second
   end if
end incrementTime

on stopTimer
   put false into sTimerOn
end stopTimer

on preopencard
   put the seconds - sStartTime into field "timeDisplay"
end preopencard
So the script local variable sStartTime contains the time the timer was started and then each time time increment is called it calculates the elapsed time and puts it in the field "timeDisplay" of the current card.

The preopenCard script will ensure that the proper elapsed time is put into the field as soon as the card opens.

Hope this helps. Good luck with the project.

Martin

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Re: Count up timer over multiple cards

Post by CammyGray21 » Thu Jan 01, 2015 7:04 pm

Thanks again for the quick reply.

I assume that in the case of using a button you could also have it so that when the original card that begins the timer opens that it can be initiated in the same way? Or is that a misconception on my part.
Thanks again.

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Count up timer over multiple cards

Post by Martin Koob » Thu Jan 01, 2015 7:25 pm

Yes you are correct, it does not have to be called in a button script. You could have a call to startTimer in the openCard script of the card you want to start the time. (Don't put it in the stack script though because that would re start the timer with each card that opened).

In the card script you would have

Code: Select all

on opencard
     startTimer
end opencard
The stopTimer could be called by anything as well, a closeCard command, a mouseUp command in a button or by some action occurring in the game. Whenever you want just call 'stopTimer' and it will stop the timer.

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Re: Count up timer over multiple cards

Post by CammyGray21 » Thu Jan 01, 2015 10:58 pm

Hey I have this as my timer script, it calls on each card from opencard, only thing is when I complete on one card and go back to the next the timer resets to 0 any help? Or would it actually be a good thing if I could send the program to someone?

Code: Select all

on updateTimer
   if time_used>=0 then
      put time_used into field "Timer"
      put time_used +1 into time_used
      send "updateTimer" to me in 1 second
   end if
end updateTimer

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Count up timer over multiple cards

Post by Newbie4 » Fri Jan 02, 2015 1:56 am

Have you declared time_used as a global everywhere that you reference it?

E.g.

Code: Select all

global time_used
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Re: Count up timer over multiple cards

Post by CammyGray21 » Fri Jan 02, 2015 12:40 pm

I have it declared as global yes but when I return to what is essentially my main card where the other cards can be accessed from the timer resets itself back to 0 again.

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Count up timer over multiple cards

Post by Newbie4 » Fri Jan 02, 2015 2:30 pm

Do you have it declared global there too? There has to be a global statement everywhere you use that variable.

Where do you reset it to zero? Could you be executing that code every time you return to the main card?
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Count up timer over multiple cards

Post by jacque » Fri Jan 02, 2015 8:02 pm

I like the grouped object approach better than putting a copy of the field on each card. It's cleaner and uses fewer resources.

Create the field that will hold the text. Group it. In the group property inspector (not the field's inspector) choose "behave as background". Then in the field's property inspector, select "shared text". That will allow the same text to be shown on every card, and when you change cards, the field will retain its content without any globals or scripting.

Place the group on any cards that need to display that field. You can use the Object menu to place the group.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Re: Count up timer over multiple cards

Post by CammyGray21 » Sat Jan 03, 2015 10:12 pm

Is there a way for me to upload the program onto the forum page? Cause I think that it would certainly help me a lot more if you guys could physically see the program too. Upload attachment doesn't seem to like it so anything please thanks.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Count up timer over multiple cards

Post by SparkOut » Sat Jan 03, 2015 10:49 pm

Zip the file first, and you should be able to upload the attachment, but you will need a minimum number of posts first (1 think 10?)

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Re: Count up timer over multiple cards

Post by CammyGray21 » Sat Jan 03, 2015 11:30 pm

Alright thanks for that, will try to get my posts up to 10 in the meantime.

CammyGray21
Posts: 17
Joined: Thu Jan 01, 2015 1:12 pm

Re: Count up timer over multiple cards

Post by CammyGray21 » Sun Jan 04, 2015 2:24 pm

Can I just ask actually, I have a maze as part of my program as sort of a minigame of sorts but it works for my windows PC but not on my Mac is it because some of the functionality doesn't port over or is there any other reason? Cheers again.

Post Reply

Return to “Games”