More than one variable for "string"?

Hello everyone. I cant seem to find the solution to the following anywhere. I’m not even sure how to describe what I want without actual code (that is incorrect mind you). 

Basically I have an alert showing through this code below.

local alert = native.showAlert( "Alert", "description string would go here.", { "OK" } )

However, I do not want the description string to be just one written out string of text. I’d like to be able to use variables that change due to something the user does, for example.

Alert1 = 0 local alert = native.showAlert( "Alert", Alert1, { "OK" } )

The code above basically will make it so the description string will be the value “0”. Which is fine, however I have more then one variable so what I need is more like .

Alert1 = 0 Alert2 = False  Alert3 = "Yes"

But doing something like below does not work. (Which I knew it wouldn’t, trying to figure out what would, if anything). 

local alert = native.showAlert( "Alert", Alert1 and Alert2 and Alert3, { "OK" } )

So what I would like is the Alert to show the Alert1, Alert2, and Alert3 variables in the string. So the final alert would be as follows.

Alert

0 False Yes

OK

Is there any way to accomplish this? If so any help would be greatly appreciated!

I may be completely misunderstanding you, but here is my estimation of what you’re asking for:

local function msg( ... ) local str = tostring(arg[1]) for i = 2, #arg do str = str .. "\n" .. tostring(arg[i]) end return str end local alert = native.showAlert( "Alert", msg(Alert1, Alert2, Alert3 ), { "OK" } )

That worked perfectly! I knew it was an easy fix. Thank you!

Hi,

A table based variation, just because.  :wink:

local function msg( vals ) return table.concat(vals, "\n") end local alert = native.showAlert( "Alert", msg( {"happy", "dog", "days"} ), { "OK" } )

-dev

I know this topic was answered but I have one more question regarding this. Is there a way to have them on the same line if exported to a .txt file? The way it is now the comma seems to basically start a new line. This works great for most of what I need but not on exporting into a .txt file. Any help would be great!

-B

I don’t understand the update to this question.

  1. Show me your inputs and
  2. Show me the expected output.

If all you want to do is get rid of the newline, replace it with a comma… I don’t understand …

replace this: "\n" with this: ","

I may be completely misunderstanding you, but here is my estimation of what you’re asking for:

local function msg( ... ) local str = tostring(arg[1]) for i = 2, #arg do str = str .. "\n" .. tostring(arg[i]) end return str end local alert = native.showAlert( "Alert", msg(Alert1, Alert2, Alert3 ), { "OK" } )

That worked perfectly! I knew it was an easy fix. Thank you!

Hi,

A table based variation, just because.  :wink:

local function msg( vals ) return table.concat(vals, "\n") end local alert = native.showAlert( "Alert", msg( {"happy", "dog", "days"} ), { "OK" } )

-dev

I know this topic was answered but I have one more question regarding this. Is there a way to have them on the same line if exported to a .txt file? The way it is now the comma seems to basically start a new line. This works great for most of what I need but not on exporting into a .txt file. Any help would be great!

-B

I don’t understand the update to this question.

  1. Show me your inputs and
  2. Show me the expected output.

If all you want to do is get rid of the newline, replace it with a comma… I don’t understand …

replace this: "\n" with this: ","