Discuss Scratch

Karajohn
New to Scratch
12 posts

Help with time inputs

I have created a clock and now I'm stuck as I have to make a set of questions that would ask of the user to tell the hour and the minute, the clock will respond accordingly to the answers and continue functioning from there.

I thought of creating a bunch of “If-then” rules but I'm sure there's a smarter way. If anyone can show it to me, would be much appreciated
Karajohn
New to Scratch
12 posts

Help with time inputs

Does anyone knows how to do it or knows of a similar Project to check on the code? What I found so far are just clocks, they don't change the time based on what the user wants, e.g. to start the clock from 4:20.
drmcw
Scratcher
1000+ posts

Help with time inputs

Yes it would be just a bunch of if-then rules. The smart way would be just to use the
(current [ v])
blocks instead of having to ask!

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
Zacshap21
Scratcher
100+ posts

Help with time inputs

I like the way you have it. Being able to change the time would be helpful for different time zones etc. you could do: ask the hour first, then set variable hour to answer, then ask the minute and set minute variable to answer.



Play Pong! against a computer player! Earn Fire and Gold Power-Ups to throw off your opponent and get the highest score possible! Click the above to play!
turkey3
Scratcher
1000+ posts

Help with time inputs

Setting the Time on the Wiki.

Karajohn
New to Scratch
12 posts

Help with time inputs

Thanx guys, but I didn't manage to do what I have to do, maybe because I didn't ask correctly.

The clock is analog, not digital. So all hands (hour, minute, second) are at Number 12 when the green flag is pressed. What I want to do is ask the user to set hour and minute, then move the hour hand and the minute hand to the appropriate places according to the answers and the clock to start functioning.

I have made it with if-then rules. For example, If the answer to Hour is 1 Then move the hour hand by 6 degrees, If it's 2 by 12, etc. This method is legit but I have to make 12 commands for the hour hand and 60 for the minute hand. There must be an easier way!

Another question. With the Move x degrees command, the hour hand moves very abrubtly. Can I make this move look smoother?
Karajohn
New to Scratch
12 posts

Help with time inputs

OK, I got it, asking questions is a way to clarify what exactly one wants to do and use the search button better, I found a clock like the one I want to create.

I still have the smoothness of the movement though, how can I make the hour hand to go the correct place -for example when the user says its 3 o clock to go to 3- in a smooth way and not so sharp?
drmcw
Scratcher
1000+ posts

Help with time inputs

define set hour hand (hour)
point in direction (0 v)
repeat ((hour) * (30))
turn right (1) degrees
end

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
Karajohn
New to Scratch
12 posts

Help with time inputs

I don't know how the set of orders you wrote will help. I will make it clearer.

This is my Project: http://scratch.mit.edu/projects/21677151/

It asks to set the time, then the minutes, the hands go to the appropriate places and its starts working.

Question 1: Why is there a lag of a second before the seconds start ticking?
Question 2: How can I make it so the hands go slower and smoother to their correct places?
drmcw
Scratcher
1000+ posts

Help with time inputs

Remix here to show the movement.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
Karajohn
New to Scratch
12 posts

Help with time inputs

You 're the best, 1000 thanx
Karajohn
New to Scratch
12 posts

Help with time inputs

Can you please explain how the code Works and makes the move of the hour hand smooth?
drmcw
Scratcher
1000+ posts

Help with time inputs

To make movement smoother you need to do lots of small movements instead of one big one. So the code works out how many rotations of 1 degree are needed to get to the required hour. For hours, each one is 30 degrees, so it makes 30 x 1 degree rotations for each hour that is required.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
Karajohn
New to Scratch
12 posts

Help with time inputs

Thank you!
Karajohn
New to Scratch
12 posts

Help with time inputs

I'm one step close to the end of the Project. I finally made it:

a) Set all hands to 12 place
b) Ask the hour and go to the appropriate place smoothly
c) Ask the minutes and go to the appropriate place smoothly
d) The second hand moves 1 degree every second

The final step is for the hour hand and minute hand to move, after they have been set to the correct place, 0.008333 and 0.1 degrees accordingly every second, so that the clock is functioning properly, because as it is now, the seconds are ticking but the hour and minute hands don't change place.

And I'm stuck, every thing I try make them move the way I want them to but they First go back to 12 place and then they move. How can I make them move without going back?

The Project is here: http://scratch.mit.edu/projects/21677151/

Last edited by Karajohn (May 8, 2014 07:47:40)

drmcw
Scratcher
1000+ posts

Help with time inputs

d) The second hand should move 6 degrees every second, which you do have in the code

You're doing a broadcast every second and the second hand receives that and moves by 6 degrees. Make the minute hand receive it and move by 0.1 degree and the hour hand receive it and move by 0.08333333 degrees. You'll get rounding errors with the hour hand but try it and see if its accurate enough for you, if not then you'll need to broadcast more than seconds.

Last edited by drmcw (May 8, 2014 09:28:45)


10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
Karajohn
New to Scratch
12 posts

Help with time inputs

d) Yes, it was a typing error

I tried what you said but with the broadcast the minute hand was going back to 12 place before it started moving, instead of starting from the place it was set in c) step. That's the problem I can't overcome
drmcw
Scratcher
1000+ posts

Help with time inputs

Karajohn wrote:

d) Yes, it was a typing error

I tried what you said but with the broadcast the minute hand was going back to 12 place before it started moving, instead of starting from the place it was set in c) step. That's the problem I can't overcome
There's nothing in the project that shows that. Make the changes and then we can see what you have done.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
Karajohn
New to Scratch
12 posts

Help with time inputs

OK, here it is. When the second hand receives the Clock_OK, it starts counting the seconds. Now I added the “Send Start_ticking” broadcast which is received by both hour hand and minute had so that they change by 0.1 and 0.008333 degrees every second respectively. They not only don't do that but they also go back to 12 place…

http://scratch.mit.edu/projects/21677151/

Last edited by Karajohn (May 8, 2014 09:22:44)

drmcw
Scratcher
1000+ posts

Help with time inputs

Ok from both when I receives, remove the forever block that is not needed. Then instead of point to use
turn right () degrees

Just noticed you have a problem elsewhere see this for solution.

Last edited by drmcw (May 8, 2014 09:34:39)


10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?

Powered by DjangoBB