inserting a variable into display.newText()

Hey everyone, I’m having a problem trying to insert some variables into a string for a text object. Here’s what I’ve got for the value in question

 text = "You are out of lives. Do you want to buy more, or wait for ".. tostring(hoursRemaining) "hours and " .. tostring(minutesRemaining) .. " minutes until until your lives reset?",

The error i get is “attempt to call a string value”. I have also tried just concatenating it as the original variables, which gives me the same error, but as a number, instead of string.As always, TIA

Hello buddy, this is the rigth way to insert a text variable:

local myText = display.newText( "Hello World!", 100, 200, native.systemFont, 16 )

For further information take a look at this link:

http://docs.coronalabs.com/daily/api/library/display/newText.html

Can you post more of your code?  There should be a line # with the error.  Knowing that and which line that is would be helpful too.

Rob

Hey dev, that doesn’t look like a variable though, or, not the way I’m intending it. Here’s the entire block of code:

 local options = { parent = g, text = "You are out of lives. Do you want to buy more, or wait for ",--.. tostring(hoursRemaining) "hours and " .. tostring(minutesRemaining) .. " minutes until until your lives reset?", --insert a function here to calculate the time difference for lives reset x = 0, y = -40, width = 250, font = native.systemFontBold, fontSize = 24, align = "center" } local text1 = display.newText(options)

basically, i want hoursRemaining and minutesRemaining (the variables) to show up in the line of text

text = "You are out of lives. Do you want to buy more, or wait for " ,–… tostring(hoursRemaining) “hours and " … tostring(minutesRemaining) … " minutes until until your lives reset?”, --insert a function here to calculate the time difference for lives reset

You have two potential syntax problems.  First the ,-- (which I colored red).  As of now, that causes the rest of the line to not be used.  Perhaps you did that to prevent the error.  You of course need to remove that.  I suspect your real error is the missing “…” which colored orange in the line.

Rob

You were indeed right Rob,  i missed the pair of …'s, and the error was non-intuitive in this case, thanks for the extra set of eyes!

Hello buddy, this is the rigth way to insert a text variable:

local myText = display.newText( "Hello World!", 100, 200, native.systemFont, 16 )

For further information take a look at this link:

http://docs.coronalabs.com/daily/api/library/display/newText.html

Can you post more of your code?  There should be a line # with the error.  Knowing that and which line that is would be helpful too.

Rob

Hey dev, that doesn’t look like a variable though, or, not the way I’m intending it. Here’s the entire block of code:

 local options = { parent = g, text = "You are out of lives. Do you want to buy more, or wait for ",--.. tostring(hoursRemaining) "hours and " .. tostring(minutesRemaining) .. " minutes until until your lives reset?", --insert a function here to calculate the time difference for lives reset x = 0, y = -40, width = 250, font = native.systemFontBold, fontSize = 24, align = "center" } local text1 = display.newText(options)

basically, i want hoursRemaining and minutesRemaining (the variables) to show up in the line of text

text = "You are out of lives. Do you want to buy more, or wait for " ,–… tostring(hoursRemaining) “hours and " … tostring(minutesRemaining) … " minutes until until your lives reset?”, --insert a function here to calculate the time difference for lives reset

You have two potential syntax problems.  First the ,-- (which I colored red).  As of now, that causes the rest of the line to not be used.  Perhaps you did that to prevent the error.  You of course need to remove that.  I suspect your real error is the missing “…” which colored orange in the line.

Rob

You were indeed right Rob,  i missed the pair of …'s, and the error was non-intuitive in this case, thanks for the extra set of eyes!