How is a variable changed to a string? ( into speach marks)

I am making a physics data request (physicsEditor) and want this:

[lua] r = math.random(1,5)
local physicsData = (require “retro”).physicsData(scaleFactor)
physics.addBody( enemy, physicsData:get® )[/lua]

It won’t work because it wants a string in speach marks.

help me? :slight_smile: [import]uid: 79135 topic_id: 15324 reply_id: 315324[/import]

Try

r = math.random(1,5) local retro = require ("retro") local physicsData = retro.physicsData(scaleFactor) physics.addBody( enemy, physicsData:get(r) ) [import]uid: 69700 topic_id: 15324 reply_id: 56557[/import]

I didn’t miss a line out, you miss the point of the question.
I know how to call physics data, and it works when I use speech marks. I want to use a variable

[import]uid: 79135 topic_id: 15324 reply_id: 56558[/import]

Got it :slight_smile:

Just tried this:

[lua] r = “”…math.random(1,5)…""[/lua]

I was just trying something stupid! haha [import]uid: 79135 topic_id: 15324 reply_id: 56559[/import]

@andrewscott, you can use the Lua inbuilt functions to do that for you, you can use the

tonumber(“5”) to convert a string to a number

or

tostring(54) to convert a number to a string as you were wanting

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15324 reply_id: 56649[/import]

JayantV , that is great thanks :slight_smile: [import]uid: 79135 topic_id: 15324 reply_id: 57367[/import]

I thought Corona does automatic conversions between strings and numbers. Isn’t that the case? [import]uid: 64174 topic_id: 15324 reply_id: 58728[/import]

Lua will convert numbers to strings and vise versa automaticly if the context is clear… hmm example

x=1
print(x…" Test Value")

…x is now a string…

x=x+1

…x is a number again…

the confustion comes when the context is not clear… Lua will then use whatever ‘type’ the value was last used as. In those cases it is best to use toNumber(x) or toString(x).

[import]uid: 40100 topic_id: 15324 reply_id: 59349[/import]

@allen, you might want to note that these are *not* camelcased

tonumber() and tostring() are lowercase functions only.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15324 reply_id: 59418[/import]

Yep…

3rd Lua implementation I have used…the minor differences give me fits at times.
:slight_smile:
[import]uid: 40100 topic_id: 15324 reply_id: 59784[/import]

IÂ?d should check with you here. Which isn’t something I usually do! I take pleasure in studying a put up that will make folks think. Also, thanks for permitting me to remark!
Levitra line literal Provigil vs nuvigil dosages panhypopituitary Vicodin filariform [import]uid: 135934 topic_id: 15324 reply_id: 96574[/import]