How do I make a continuous event on click

Get help using Construct 2

Post » Wed May 03, 2017 1:41 pm

I have a clock that the students must put at a certain time by clicking up or down arrow images or using the keyboard. The minutes hand is set to rotate in 30 degrees increment that is 5 minutes increments (no times like 12:03 in the questions) and the hours are set in 2.5 degrees increment (as a normal clock).

I would like the possibility to just press the up or down arrow that represent clockwise and counterclockwise to move the hands without having to click for each rotation and when release to stop where they are.

How can I accomplish that. I was thinking about something like i++ in javascript but not sure how that works in C2.
B
8
S
1
Posts: 86
Reputation: 618

Post » Wed May 03, 2017 1:45 pm

Found the solution - using touch in touch and setting to 1 degree so it is not too fast.
B
8
S
1
Posts: 86
Reputation: 618

Post » Wed May 03, 2017 3:02 pm

It's actually hard to manage on a continuous move of the hands which works with touch in touch because of the lack of precision in the moves.

The way I had it before on touch on touch was this:
Image

I added the variables minute and hour because I compare these in order to find out it they got the time correct. I have the correct answers for minutes, hours, and AM or PM in arrays. Of course it does not work when going clockwise because I get negative number and I probably need to reset the minutes to 60 to subtract from 60 instead of 0 in that direction.

Hum...

Thinking about it...

I am thinking that maybe I need to just calculate the minutes compare to a whole day (60*24) instead. That way for example 7:30 PM would be in military time 19:30 or 19*60 + 30. Does this make sense?


The code here is:
B
8
S
1
Posts: 86
Reputation: 618

Post » Fri May 12, 2017 1:26 pm

I gave up the continuous event using on touching because it is just too fast to be able to stop at the correct time that needs to match the question. Instead I increment or decrement by 5 and rotate 30 degrees for minutes and 2.5 degrees for hours. Both are going at the same time like a regular clock.

This is different than setting up a clock for which there is a tutorial on this forum which I just discovered.
https://www.scirra.com/tutorials/1450/v ... -24h-clock

Since the student is the one who moves the hands the setup has to be different. I have a down button to go counterclockwise and a up button to go clockwise.

This was more complicated than just setting up a digital clock that goes only clockwise on its own.

I found the anwser for this if it helps someone. I decided to use only minutes in the background to make checking variables easier. Then I convert the time for the digital clock that is needing to be the same as the analog clock.
Code: Select all
Global variables
hourText
minuteText
// conversion
set hourtext to int(timer/60)
set minuteText to int(timer % 60)


1- I check to see if the time chosen is AM or PM.
2- The starting point has to be checked depending on AM or PM (see below)
3- for the display I use this on every tick:
Code: Select all
if hourtxt <12 then set text to right("00" & hourText,2) & ":" & right("00" & minuteTxt,2) & " " & timeChoice
if hourtxt >11 then set text to right("00" & hourText-12,2) & ":" & right("00" & minuteTxt,2) & " " & timeChoice

So now it is all working.

Resetting the timer variable in order to have the correct start time depending on AM or PM
Code: Select all
// global variables:
timeChoice = ""
timer = 0

//UP/Clockwise button:
if timer = 0 and timeChoice = "AM"  set timer to 0
if timer = 0 and timeChoice = "PM" set timer to 720

//DOWN/Counterclockwise buttton:
if timer = 0 and timeChoice = "AM"  set timer to 720
if timer = 0 and timeChoice = "PM" set timer to 1440
if timer = 720 and timeChoice = "PM" set timer to 1440
B
8
S
1
Posts: 86
Reputation: 618


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, Yahoo [Bot] and 5 guests