Aparna
Aparna

Reputation: 845

In Lua how to associate a numeric value to an object

I have just started coding in Lua(corona). I have an image.

local egg=display.newImage("egg.jpg")

Now I want to display a random number on the image and associate that image with it. Like if this image collides with another object, I need to retrieve the value of the random number. How can this be done?

Upvotes: 0

Views: 75

Answers (1)

dannash918
dannash918

Reputation: 454

In lua, you can just add properties to any object.

local myRandomNumber = math.Random()
local egg = display.newImage("egg.jpg")
egg.numberValue = myRandomNumber

So to retrieve that value you would just access the numberValue property

To know more about random numbers you can read here

http://lua-users.org/wiki/MathLibraryTutorial

Upvotes: 1

Related Questions