Making things appear HELP!

OK, so I am trying to figure out this whole getting a sprite or image to appear once something happens. In this case I need the images or sprites to appear once the sum of the dice is figured out. Can anyone help me out?

main.lua
[lua]os.execute (“cls”)

display.setStatusBar (display.HiddenStatusBar)

require “sprite”

local bckgrnd = display.newRect (0, 0, 480, 320)
bckgrnd.y = 160
bckgrnd.x = 240
bckgrnd:setFillColor (20, 124, 12)

local table = display.newImage (“craps.2.png”)
table.y = 170

local diceTotal = 0

local canRoll = true

local diceSheet = sprite.newSpriteSheet( “Dice3.png”, 64, 64)

local Roll = display.newImage (“roll.png”)
Roll.y = 280
Roll.x = 250

local diceSet = sprite.newSpriteSet (diceSheet, 1, 6 )
sprite.add( diceSet, “Dice1”, 1, 6, 195, 0)
sprite.add( diceSet, “Dice2”, 1, 6, 210, 0)

local dice = sprite.newSprite( diceSet )
dice.x = 100
dice.y =185
dice:prepare(“Dice1”)

local dice2 = sprite.newSprite( diceSet )
dice2.x = 350
dice2.y = 85
dice:prepare(“Dice2”)

local two = display.newImage (“casino#2.png”)
two.x = 225
two.y = 150
two.isVisible = false

local three = display.newImage (“casino#3.png”)
three.x = 225
three.y = 150
three.isVisible = false

local four = display.newImage (“casino#4.png”)
four.x = 225
four.y = 150
four.isVisible = false

local five = display.newImage (“casino#5.png”)
five.x = 225
five.y = 150
five.isVisible = false

local six = display.newImage (“casino#6.png”)
six.x = 225
six.y = 150
six.isVisible = false

local seven = display.newImage (“casino#7.png”)
seven.x = 225
seven.y = 150
seven.isVisible = false

local eight = display.newImage (“casino#8.png”)
eight.x = 225
eight.y = 150
eight.isVisible = false

local nine = display.newImage (“casino#9.png”)
nine.x = 225
nine.y = 150
nine.isVisible = false

local ten = display.newImage (“casino#10.png”)
ten.x = 225
ten.y = 150
ten.isVisible = false

local eleven = display.newImage (“casino#11.png”)
eleven.x = 225
eleven.y = 150
eleven.isVisible = false

local twelve = display.newImage (“casino#12.png”)
twelve.x = 225
twelve.y = 150
twelve.isVisible = false

–End Roll Function
local function endRoll()
dice:pause()
dice2:pause()
diceTotal = dice.currentFrame + dice2.currentFrame
print(diceTotal) --Print the result in the terminal
canRoll = true --Allow the dice to be rolled again

end

–Roll function
local function rollDice()
if canRoll == true then
canRoll = false --Prevent dice from being rolled again before the current role is over
dice:play()
dice2:play()
randomTime = math.random(6000, 6000)
timer.performWithDelay(randomTime, endRoll, 1)
end
end
Roll:addEventListener(“tap”, rollDice)

local RollMusic_mp3 = audio.loadStream (“Music Super Mario Kart - Item Box (Ding, Ding).mp3”)

function Roll:tap (event)
audio.play (RollMusic_mp3)
end

Roll:addEventListener (‘tap’, Roll) [import]uid: 129092 topic_id: 24920 reply_id: 324920[/import]

Took me a while to work out what you might see as a problem here.
Im guessing its because after you add the dice scores, you have a number from 1 to 12

But the number images are referenced by words such as one , nine, etc

The easiest answer is to create an array of these images.

Code that follows is ‘off the top of my head’ … apologies for any syntax errors…

local sums{}  
  
local nine = display.newImage ("casino#9.png")  
nine.x = 225  
nine.y = 150  
nine.isVisible = false  
sums[9] = nine  

or maybe

sums[9] = display.newImage ("casino#9.png")  
sums[9].x = 225  
sums[9].y = 150  
sums[9].isVisible = false  

or maybe do them all in one shot like this:

local img  
for img = 1, 12 , do  
sums[img] = display.newImage ("casino#"..img..".png")  
sums[img].x = 225  
sums[img].y = 150  
sums[img].isVisible = false  
end  

(…or even have the image which displays the sum be a sprite itself, and just set the currentFrame once you know the total.)
and then you show the image you want by using

local function endRoll() dice:pause() dice2:pause() diceTotal = dice.currentFrame + dice2.currentFrame print(diceTotal) --Print the result in the terminal local lupe for lupe = 1,12,do sums[lupe].isVisible = (lupe == diceTotal) end canRoll = true --Allow the dice to be rolled again end [import]uid: 108660 topic_id: 24920 reply_id: 101207[/import]