Hey I'm new doing an assignment and I just can't get the date to show

local todaysDate = os.date("*t")

  print(string.format(“Todays date is: %d/%d/%d”, todaysDate.month, todaysDate.day, todaysDate.year))

   todaysDate.x = display.contentCenterX

    todaysDate.y = display.contentCenterY

Hey I don’t understand why this doesn’t work I’m trying to get the date and time to show in the middle of the screen, please help thank you.

Hi @81288,

Well basically, your variable “todaysDate” is simply a variable, nothing else (in this code). To display it on screen as text, you need to create a text object and then assign the value of “todaysDate” to it, so then it will appear on the screen. Once it’s a display object (text object), you can position its x and y values.

This should help you out:

https://docs.coronalabs.com/api/library/display/newText.html

Take care,

Brent

Hi @81288,

try this code:

local todaysDate=os.date("\*t") local showText="Todays date is:"..todaysDate.month.."-"..todaysDate.day.."-"..todaysDate.year print (showText) local onScreen=display.newText({text=showText,x=display.contentCenterX, y=display.contentCenterY})

line 1, get the date to a table (that you knew)

line 2, pass to a string all the variables you needed from the table

line 3, show the string “showText” on the console of corona (print will only show in console, is useful when we are debugging, for example)

line 4, show the string “showText” on screen as you wanted. Brent gave you the correct link to display objects on screen.

don’t be offended (it’s not my intention) but you really should start from some sort of tutorial or from here:

https://coronalabs.com/resources/tutorials/getting-started-with-corona/

if I had to rate your question on a scale of 0 to 100 on difficulty, it is a -1.

regards,

Carlos

Hi @81288,

As Carlos says, you should start with a basic tutorial. The “official” recommendation is our Getting Started guide which will let you build a simple game from the ground up, teaching you Corona basics along the way:

https://docs.coronalabs.com/guide/programming/intro/index.html

Brent

Hi @81288,

Well basically, your variable “todaysDate” is simply a variable, nothing else (in this code). To display it on screen as text, you need to create a text object and then assign the value of “todaysDate” to it, so then it will appear on the screen. Once it’s a display object (text object), you can position its x and y values.

This should help you out:

https://docs.coronalabs.com/api/library/display/newText.html

Take care,

Brent

Hi @81288,

try this code:

local todaysDate=os.date("\*t") local showText="Todays date is:"..todaysDate.month.."-"..todaysDate.day.."-"..todaysDate.year print (showText) local onScreen=display.newText({text=showText,x=display.contentCenterX, y=display.contentCenterY})

line 1, get the date to a table (that you knew)

line 2, pass to a string all the variables you needed from the table

line 3, show the string “showText” on the console of corona (print will only show in console, is useful when we are debugging, for example)

line 4, show the string “showText” on screen as you wanted. Brent gave you the correct link to display objects on screen.

don’t be offended (it’s not my intention) but you really should start from some sort of tutorial or from here:

https://coronalabs.com/resources/tutorials/getting-started-with-corona/

if I had to rate your question on a scale of 0 to 100 on difficulty, it is a -1.

regards,

Carlos

Hi @81288,

As Carlos says, you should start with a basic tutorial. The “official” recommendation is our Getting Started guide which will let you build a simple game from the ground up, teaching you Corona basics along the way:

https://docs.coronalabs.com/guide/programming/intro/index.html

Brent