2014년 12월 13일 토요일

2 Stop Watches: START and STOP to STOP and START???


I have 2 Stop Watch Clocks: This is how it's supposed to work > Clock 1 Starts then Clock 2 Stops and if Clock 2 Starts Clock 1 Stops but, when either or Stops and the other one Starts off at the same exact timing the other Clock Stopped at and not at the time it left off last with... (If that makes sense?) Which is the Correct way it's supposed to work!

--
I do not know what the correct way is, because that is the way you want it to work.
Why do you need two clocks if one always continues where the other stops?

--
What SHOULD HAPPEN: Clock 1 Stops and Clock 2 Starts "Vice Versa" Clock 2 Stops and Clock 1 Starts but, *the (issue)* I'm having is when "Either Clock 1 or Clock 2 Starts again it Starts off at the SAME EXACT time the other Clock left off/Stopped and NOT the time it stopped at!" I hope that better explains it???"


What SHOULDN'T HAPPEN: "Either Clock 1 or Clock 2 Starts again it Starts off at the SAME EXACT time the other Clock left off/Stopped at and NOT the time it itself stopped at!" 

Edit: (e.g.) Both Clocks 1 and Clock 2 Set at 2:00 mins... When Clock 1 is Clicked ..Clock 2 Starts... When Clock 2 is Clicked (Clock 2 Stops (at 1:32 mins/secs) and Clock 1 Starts (at 1:32mins/secs) < "Not Supposed to happen" Clock 1 Should Start at 2:00mins and continue... back and forth till time is done on either clock first!

--
Still confusing, but I still think you are saying:
Clock1 stops at time1
Clock2 should start at time1
Clock2 stops at time2
Clock1 should start at time2 (and not at time1, as apparently happens now)

Still my question is, why would you need 2 clocks then?

Well: time to post a screenshot of your blocks, maybe we can see then what is wrong.

--
Check my Edit... I'll try posting a Screenshot ASAP! Thank you for replying and Help! I really appreciate it!

--
Like a Chess Clock..

--
You are probably confusing your references to the timers.  If you want help, post screenshots of your blocks so we can see what you're doing and how you're doing it.

--
Let me know if you need others! Thank you again!






--
I don't see any place where you're clearing the globals and resetting the times.

--
I googled on how a chess clock should work, and I think it is this:
Clock1 and Clock2 have both a certain total time.

Clock1 starts at total and stops at time1a
immediately Clock2 starts at total and stops at time2a

immediately Clock1 starts at time1a and stops at time1b
immediately Clock2 starts at time2a and stops at time2b etc...

However, you should keep the time for each clock in a **separate** global. And you have redundant routines in the when.Timer events. You could use a procedure with as input the appropriate timer. This would make your life simpler.

--
I see why you wanted to Visually see it to better understand what I meant! Cause now I need the same lol... and Examples of what you mean here "However, you should keep the time for each clock in a **separate** global. And you have redundant routines in the when.Timer events. You could use a procedure with as input the appropriate timer. This would make your life simpler."

--
Please read my tips on redundancy and procedures:


--
Thank you BOTH for All your help! I'm really new to this all this and App Inventor... but, I'm learning though so any Tips, Good Tutorials, etc.. is MUCH appreciated! I'm looking into all the info you gave me... Thank you BOTH again!

--
When your app starts, each clock has a certain time which should be counted down to 0. When one of the clocks counts down to 0 the player with that clock looses.
For starters, you could calculate the total amount of seconds allowed to each player, that would save you the global sec and global min. 
Then, you should have global ts1 for clock1 and global ts2 for clock2 initialized or set to the total number of seconds each player has.

  in when Clock1.Timer you say set global ts1 to get global ts1 - 1
  in when Clock2.Timer you say set global ts2 to get global ts2 - 1
and: when 0, this particular player with that clock looses.

Now, I think you want to display the time in minutes and seconds in a label for each player instead of the seconds you have in this new setup. You may have a procedure with as input either ts1 or ts2 (read the documentation on how to create a procedure with inputs and Enis his tips), which could return the value you need to be displayed on the label. Call this procedure in each when Clockx.Timer event block.
Slightly clearer? If not, AND if you have tried to figure out how procedures work, then upload an .aia and I will try to help you. 

--
Just read the posts and just want to clarify something for you. The way app inventor works is that everything is run one block a time and does not run in parallel unfortunately, so even if you have 2 clocks running the timer blocks won't be process at the same time. The one timer event block will run and all block code with in it will be processed. Once that has been completed then the second timer event block will be process.

It is better practice I find just to use 1 clock component to do all process. 

--
Never even thought of that Gareth... very nice catch!

--
I'm gonna read up more before I reply with my findings and results of all the information you'll have provided for me! :D Thanks for the insight..

--
I don't think many users App Inventor are aware of how block code is processed and in certain projects this can be quite important to understand so you can create work a rounds to solve the issue of sequential processing in AI. 

If your interested, Jose has written a great blog discussing how App Inventor block code is processed when a project is run in more detail. Here's the link: The simple Virtual life

--
Yes, of course you are right and also Jos his write up is nice, I did not see it before.
However, apart from scaring The End, I think this is not a valid issue here. Because there is always only one clock enabled in his case.
Actually, he could easily use one timer. He only needs two counters, but it would be slightly more difficult to figure out from which counter he should subtract when the timer event fires. Apart from that, this is not rocket science where every millisecond counts, but a chess clock, where slow human reaction causes more inaccuracy than sequential processing.

--
Using 1 timer you could do something like this

--
Any of you on Hangouts? I'm getting lost... I know it's probably a few simple changes  to the code that need to be done but, it's hard for me to see plus this it honestly my first run at trying to create a app period.

Ghica are you on Google Hangouts?

--
Attached is a the Chess clock AI2  project I just created which does what you are after I think.

The figure 86400 in the project is number of seconds in 24 hours. to calculate this 60secound * 60minutes * 24hours = 86400 second if your wand to do mil-seconds aswell this can be done. The formula could be made much simplier I'm pretty sure taking the system time at the start away from the current system time


--
Hey Gareth, Thanks for your help on the .aia file! I'm trying to get the Milliseconds running, but can't seem to figure it out! I'm not sure if I NEED to have the Clocks Timerinterval set to 100 or if I can leave it at 1000? 

Not sure if its something in I'm not doing correct in linking the coding for the Milliseconds or what? 

I'd appreciate your help.. I'm pretty sure it something simple I'm missing idk... I just need the milliseconds to count down from 9-0 and 0-9.. 

--
Clock intervals are 1000 per second, so 5000 would be 5 seconds, 1000 is one second, 500 is 1/2 a second and 100 is 1/10th of a second.

--
Hi The End and Gareth,
This is going to be the clock contest! I had made an .aia too, but when I saw that you had made one too, I kept it.
But looking at yours, I think for a real chess clock there are some flaws.
I think that when you press button 1, the clock for player 2 should start running, because it signifies that Player 1 is ready, And the other way around.
It would be nice to disable the button of the player not playing.
Another thing is that the phone falls asleep after a minute or so and then the clock stops running. 
To prevent that I used a trick I read somewhere: Have a second clock with a rather larger timer and a notifier with transparent background and empty alert message in the when Clock2.Timer ...
To make it easy for The End, I implemented the millisecond part (the timer interval should be set to 100). But why do you need milliseconds for a chess clock? And when should they count from 0-9??


--
Thanks for both of your replies..
So I spoke with Gareth on "Google Hangouts" and basically gave him this site (http://www.online-stopwatch.com/full-screen-chess-clock/) as a Base of what I was looking for Both Timers to look like.. minus the 1000 Milliseconds (I just need it to count from 1/10th of a Second) for the 1 min games mostly but, need it to run for Alll the times "If I can get the clock to run just like that site it'll be Awesome but, if not its fine.. and it's just visually better! imo.. and the Start Button isn't needed... So I believe Gareth just made a Quick Template for me to get a idea of how I could code it..

I have everything set it's just the milliseconds thats not kicking in the way it's supposed to... I'm gonna take a look at your code now! 
Thank you all again!

--
I'm think I burnt a few Brain Cells lol! Geesh! I guess theres sooo many ways to write this code for something that looks so simple from the outside looking in!

If you don't mind taking a look at the screen shoots to see where in the Milliseconds thats just not adding up literally!? I tried to just follow the code Gareth provided.. but, I definitely got Great ideas from your layout @Ghica! 






--
From the pictures I cannot figure out what you did, so if you want an answer, you must attach an .aia and I will look at it maybe tomorrow.

Anyway, it is a bit tricky. I have the counters of the time in an array. At the beginning I look what the number of minutes is and I multiply that with 600. Now you have the time for each player in tenth of seconds (which is also the time interval for the clock).

At each timer event, you can now just subtract 1 from one of the counters (the counter for the current player). If the counter is <= 0, the game is over. 

If you want to display the time left, you have to do some calculations:
Get the count in tenths of seconds (hmilli in my blocks). You already have it that way, but you must take the right list element.
The number of seconds is floor(hmilli/10).  the number of seconds is hmilli / 10 and you want the highest integer smaller than that.)
To find the minutes and seconds division, you do quotient(sec / 60) which is actually the same as floor. The seconds are the modulo of the seconds and 60, just actually the same as the remainder of sec / 60. The tenth of seconds is similar, but now the remainder of hmilli / 10. (hmilli was tenth of seconds and this remainder is therefore a number  0-9 as a fraction of a second. 
Look at my setLabelText procedure, it is much easier to see there. The trick is to keep the counters in tenth of seconds, the same as the time interval of the clock.

--
Ghica are you able to use Google Hangouts? I rather send the (aia) file via Hangouts if you don't mind? I'm gonna take a look at you aia file more in depth and see if I can catch it..

Thanks you for spending all this time trying to help me! I can't say that enough! 

--

댓글 없음:

댓글 쓰기