Hi guys,
I want to create a variable “money = 0” and to display it,but not only that.
Here is the code:
local Money = display.newText(“Novac:”, 60, -15, nil, 30)
local myRandomNumber1 = math.random(1,5)
box1 = display.newImage( “Box1.png” )
box1.x = display.actualContentWidth/6
box1.y = display.actualContentHeight/10
box1:scale( 0.5, 0.5 )
box1.numberValue=myRandomNumber1
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box1Text = display.newText({x = box1.x, y = box1.y, text = tostring(box1.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box1:addEventListener( “touch”, onObjectTouch )
local myRandomNumber2 = math.random(1,5)
box2 = display.newImage( “Box1.png” )
box2.x = display.actualContentWidth/2.6
box2.y = display.actualContentHeight/10
box2:scale( 0.5, 0.5 )
box2.numberValue=myRandomNumber2
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box2Text = display.newText({x = box2.x, y = box2.y, text = tostring(box2.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box2:addEventListener( “touch”, onObjectTouch )
local myRandomNumber3 = math.random(1,5)
box3 = display.newImage( “Box1.png” )
box3.x = display.actualContentWidth/1.66
box3.y = display.actualContentHeight/10
box3:scale( 0.5, 0.5 )
box3.numberValue=myRandomNumber3
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box3Text = display.newText({x = box3.x, y = box3.y, text = tostring(box3.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box3:addEventListener( “touch”, onObjectTouch )
local myRandomNumber4 = math.random(1,5)
box4 = display.newImage( “Box1.png” )
box4.x = display.actualContentWidth/1.22
box4.y = display.actualContentHeight/10
box4:scale( 0.5, 0.5 )
box4.numberValue=myRandomNumber4
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box4Text = display.newText({x = box4.x, y = box4.y, text = tostring(box4.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box4:addEventListener( “touch”, onObjectTouch )
local myRandomNumber5 = math.random(1,5)
box5 = display.newImage( “Box1.png” )
box5.x = display.actualContentWidth/6
box5.y = display.actualContentHeight/4
box5:scale( 0.5, 0.5 )
box5.numberValue=myRandomNumber5
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box5Text = display.newText({x = box5.x, y = box5.y, text = tostring(box5.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box5:addEventListener( “touch”, onObjectTouch )
local myRandomNumber6 = math.random(1,5)
box6 = display.newImage( “Box1.png” )
box6.x = display.actualContentWidth/2.6
box6.y = display.actualContentHeight/4
box6:scale( 0.5, 0.5 )
box6.numberValue=myRandomNumber6
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box6Text = display.newText({x = box6.x, y = box6.y, text = tostring(box6.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box6:addEventListener( “touch”, onObjectTouch )
local myRandomNumber7 = math.random(1,5)
box7 = display.newImage( “Box1.png” )
box7.x = display.actualContentWidth/1.66
box7.y = display.actualContentHeight/4
box7:scale( 0.5, 0.5 )
box7.numberValue=myRandomNumber7
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box7Text = display.newText({x = box7.x, y = box7.y, text = tostring(box7.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box7:addEventListener( “touch”, onObjectTouch )
local myRandomNumber8 = math.random(1,5)
box8 = display.newImage( “Box1.png” )
box8.x = display.actualContentWidth/1.22
box8.y = display.actualContentHeight/4
box8:scale( 0.5, 0.5 )
box8.numberValue=myRandomNumber8
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box8Text = display.newText({x = box8.x, y = box8.y, text = tostring(box8.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box8:addEventListener( “touch”, onObjectTouch )
local myRandomNumber9 = math.random(1,5)
box9 = display.newImage( “Box1.png” )
box9.x = display.actualContentWidth/6
box9.y = display.actualContentHeight/2.5
box9:scale( 0.5, 0.5 )
box9.numberValue=myRandomNumber9
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box9Text = display.newText({x = box9.x, y = box9.y, text = tostring(box9.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box9:addEventListener( “touch”, onObjectTouch )
local myRandomNumber10 = math.random(1,5)
box10 = display.newImage( “Box1.png” )
box10.x = display.actualContentWidth/2.6
box10.y = display.actualContentHeight/2.5
box10:scale( 0.5, 0.5 )
box10.numberValue=myRandomNumber10
local function onObjectTouch( event )
if ( event.phase == “began” ) then
local box10Text = display.newText({x = box10.x, y = box10.y, text = tostring(box10.numberValue), fontSize = 15, font = native.systemFont })
end
return true
end
box10:addEventListener( “touch”, onObjectTouch )
So,I want to,if the box1 is touched and “myRandomNumber1” displayed some number from 1,5,that generated number and displayed to add in my variable money.
Please help