How do I make a continuous event on click

0 favourites
  • 4 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • 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.

  • Found the solution - using touch in touch and setting to 1 degree so it is not too fast.

  • 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:

    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:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    Global variables
    hourText
    minuteText
    // conversion
    set hourtext to int(timer/60)
    set minuteText to int(timer % 60)[/code:5ox8tjk7]
    
    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:5ox8tjk7]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[/code:5ox8tjk7]
    So now it is all working. 
    
    Resetting the timer variable in order to have the correct start time depending on AM or PM
    [code:5ox8tjk7]// 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[/code:5ox8tjk7]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)