Time chooser - hours and minutes

Hi, does anyone have a good way for selecting numbers for hours and minutes? I would like my game to have a setting where the user can pick a start and end time, for example 9:00am to 4:30pm. Then I’ll use those times to limit when things can happen.

I tried the Draggable slider control extension as an experiment for the start time. For now I just had the slider value displaying in a text box (I’d figure out how to make it all connect later). But if I have it set up with a mininum value of 0 for midnight and 23.5 for 11:30pm with increments of 0.5 for 30 minutes then it would, for example, display 9.5 for 9:30.
image

image


I also tried the new object from the latest GD release called **Text Input** and its up and down arrows work nicely for selecting a number when the input type is set to number, but it doesn't have the limits that hours and minutes have. So, for example, the minutes value would continue past 59 and also could have negative numbers. I tried adding an event so that when the value was on 59...but there wasn't anything I could do that would allow it to still be able to go back down to a lower value. The reason why the first number is so far to the left is because of the space needed for the up and down arrows. And I would really be happy with the times limited to increments of 15 or 30 minutes, 9:07 isn't necessary for me.

image


Am I having a mental block on this and there is an easy way? Or do I need to make an extension to do it? I don't have any experience of making extensions but will give it a go if necessary although this time picker thing is for my side project. Or should I request that a Time input type be added to the Text Input object?

You may be able to convert it easily yourself with a Javascript code event. Here’s a link to something that sounds very similar to your query.

Here’s an example of how you’d pass and set variable values in the Javascript event. In this case, a scene variable _object_name has the words “Editing” and “White” removed, and the result put back into the same variable :

I don’t know if we’re talking about the same thing. I already made a clock as an experiment for a different thing and much simpler than the javascript clock video I’d seen. But I don’t think it’s useful to me? It wasn’t for display though, and it had the visual limitation of not showing a zero before a single digit number. This is what I did:




I want to constrain user input so that the numbers make sense for hours and minutes. I think that person in your link wanted to convert one time format to a different time format? Sorry if I’ve missed the point.

I kind of get it a little bit more, that person wanted to convert say, 9.5 to 9:30. Yes, well, I don’t know, I’ll have to think about it.

This is what I’ll try later using no javascript. MrMen, that link helped, thank you.


sliderValue = draggable slider value
= 9.5

timeHour = (floor) sliderValue     
= 9

sliderMin = sliderValue (mod) timeHour
= the remainder of 9.5 / 9
= 0.5

timeMin = sliderMin * 60
= 30

time = timeHour + ":" + timeMin
= 9:30

And then see what I can do with that.

1 Like