GDevelop-examples icon indicating copy to clipboard operation
GDevelop-examples copied to clipboard

TIME JavaScript (simple code)

Open sleepbedtime opened this issue 3 years ago • 4 comments

In this example you will see how to display real time in a very simple way via javascript editor.

I made it so that there are no gaps. For example: 4: 7: 8 is 04:07:08

Checklist

  • [x] I've followed all of the best practices.
  • [x] My game has a proper name in the game properties.
  • [x] My game package name behind with com.example..
  • [x] My game has all events unfolded.
  • [x] I've added myself as the author in the game properties.
  • [x] I've included a file called "README.md" with a description in proper English, explaining what this example is doing.
  • [x] I confirm that this game and all of its resources can be integrated to this GitHub repository, distributed and MIT licensed.
  • [x] I've cleaned unused resources.

Game folder

Time System Gdevelop5.zip

sleepbedtime avatar Nov 25 '21 20:11 sleepbedtime

Hi, Nice example Here is my review

  • This: var currentHours = today.getHours(); var currentMins = today.getMinutes(); var currentSecs = today.getSeconds();

Does the same as: var currentHours = ('0'+today.getHours()).substr(-2);
var currentMins = ('0'+today.getMinutes()).substr(-2);
var currentSecs = ('0'+today.getSeconds()).substr(-2);
Then why add 0 and then remove it using substr?

  • There is a unused NewExternalLayout, please remove it
  • There is no real reason to have the JS events inside a external event. Move to the Event sheet
  • Change the package name to com.example.systemtime
  • There is an invalid resource. Please remove it
  • You can change the background color by right clicking in the scene editor -> Scene properties -> Scene background color. No need to use an action
  • It is not important that the scene variable name is the same as the var in the Js codeblock. It's the opposite (as far as I know). In the Js codeblock, your are getting the value of the scene variable. So, the comment is a bit misleading
  • There is an unsed year scene variable
  • Initialize the variable time in the variables editor
  • There is an unused instance variable of the text
  • Please follow the best practices

:)

Midhil457 avatar Nov 27 '21 10:11 Midhil457

Hello, thank you for your interest 2021-11-28 16_36_05-GDevelop 5 - C__Users_FX_Documents_Time System Gdevelop5_SystemTimeJS json _ . I tried to put this code instead of mine, but what I get is a clock where there is no “0” in the first place. That doesn't really look good to me

2021-11-28 16_37_07-Preview of System Time

I will try to explain a bit how my code works (picture below)

As you can see. Our program first gets a "0", then gets a "number" from the system time. But if the system gives only the second number in a row, "0" is still valid in our code. If we get both two numbers, then we subtract 0.

2021-11-28 16_33_50-GDevelop 5 - C__Users_FX_Documents_Time System Gdevelop5_SystemTimeJS json _ SysTime2.0.json.zip

sleepbedtime avatar Nov 28 '21 16:11 sleepbedtime

Please include the whole project file and not only the json file :)

My bad for misunderstanding the use of the code :sweat_smile:

Midhil457 avatar Nov 30 '21 13:11 Midhil457

What about submitting an extension instead of an example?

D8H avatar Apr 23 '22 16:04 D8H