Ask here your questions to get help using GDevelop.
By MobileNoob
#65480 Hi Folks,
I am interested in adding a clock to my game displaying the current Time (am/pm) with no seconds just hours and minutes, and the current date (day,month, year).

But I am unsure on how to do it, and have it update whilst in game.

Any help appreciated.

thanks

MobileNoob
User avatar
By Lizard-13
#65481 There are some expressions to do it:
GetTime.png
GetTime.png (184.32 KiB) Viewed 1573 times

You can save the values in some variables as I'm doing in the image, then use the variables to change a text object string or something :)

:!: :!: :!: If you are using the web platform (HTML5), take care of the functions "mday" and "wday" because they are broken in that platform, if you need them just modify the file located at:
Code: Select allGDevelopInstallationDirectory/JsPlatform/Runtime/events-tools/runtimescenetools.js

Change the line 111:
Code: Select allreturn now.getdate();        >>       return now.getDate();

and the line 117:
Code: Select allreturn now.getday();        >>       return now.getDay();

Notice it's just a lowcase > uppercase letter change :)
By MobileNoob
#65483 Thanks for the reply Liz.

Was a bit confused about Month though, because

Do = Time(mon) to Global Variable Month

returns 0 for January.

I tried to add 1 to Global Variable Month

Do = GlobalVariable(Month) + 1 to Global Variable MonthAdj

Edit: That in fact worked for Month and similarly for year by adding 1900.

However with time 11:06 displays as 11:6 -> any ideas ?
Edit Solution attached in Screen grab -> is this the best way ?

And how do I get an am/pm rather than 24hour clock ?

thanks for the tip on the js file have edited it.
Attachments
Clock.jpg
Clock.jpg (274.59 KiB) Viewed 1537 times
User avatar
By Lizard-13
#65485 Right now you are adding a "0" before the minutes, no matter the minutes value. You should check if minutes is < 10, if so add a "0" before, this way you convert 1, 2, 3 into 01, 02, 03. But don't add a "0" if minutes is >= 10, otherwise you'll convert 12 into 012 :)
Code: Select allConditions: No conditions (always)
Actions: Do = Time(min) to global variable Minute
         Do = GlobalVariableString(Minute) to the text of global variable MinuteString

Conditions: Global variable Minute is < 10
Actions: Do = "0" + GlobalVariableString(Minute) to the text of global variable MinuteString

Now the variable MinuteString has the value with the the extra "0" if needed, you can use the variable Minute in maths (because it's a number), and use MinuteString to display it in text objects (you can't use it for maths because it's a string, "09" for example).
By MobileNoob
#65486 Thanks Liz.

I am working on a codebase for a clock as we speak.

I will upload it here as a resource when complete.

I am aiming for the following format;

10:23AM Saturday 10th of March 2018

The reason for the format is that I live in Australia (DD/MM/YY),
but the US format is (MM/DD/YY),
so by expressing it this way, it is in an International format.
Will let you know how I go, I am a slow coder so it may take a few days for me to perfect it !

MobileNoob
User avatar
By Lizard-13
#65488
The reason for the format is that I live in Australia (DD/MM/YY),
but the US format is (MM/DD/YY),
so by expressing it this way, it is in an International format.

Here in Latin America we use the same format (DD/MM/YY). Of course I'm subjective, but this format is more "international" I think, and has more sense (day D of the month M of the year Y) :evil:

Although I do like the format on the Forum

You can change the format in Account settings >> Board preferences, if you don't like it anyway ;)
By MobileNoob
#65518 Hi Folks,
I am still having trouble on understanding how to anchor the clock to the right hand side of the screen.

eg; right justified 30pixels from the right of screen with a screen width of 600 pixels.

Any help appreciated.

thanks

MobileNoob
User avatar
By Lizard-13
#65519 An action like this one just after setting the clock string should do the trick:
TextPosition.png
TextPosition.png (2.63 KiB) Viewed 1445 times