First I would like to thank all of you for the help…
I did my code and it´s working ALMOST fine… but now I´m fighting trying to clear the random numbers when I click the RIGHT mouse button, but it´s giving me some kind of error and the documentation doesn´t help too much.
Here is the main program:
I marked in red colour where I´m having difficulties.
What I´m doing wrong?
Thank you once more!
display.setStatusBar( display.HiddenStatusBar )
display.setDefault( “background”, 0.2, 0.2, 1.0 )
local PrgText = display.newText( “This program will generate two random numbers”, 500, 120, native.systemFont, 45 )
local TapText = display.newText( “Please click anywhere on screen”,500,240, native.systemFont, 40)
– Called when a mouse event has been received.
local function onMouseEvent( event )
if event.isPrimaryButtonDown then
–pickup screen coordinates at click point to make a more natural random seed
local X = (event.x)
local Y = (event.y)
–creates the random seed variable based on position and time
local seedXY = ((X/Y)*(os.time()) )
math.randomseed(seedXY)
–creates two variables to store random numbers from 1 to 100
local trnd1 = math.random(1,100)
local trnd2 = math.random(1,100)
–if the random values are equal, randomize second value again
if trnd2==trnd1 then
local trnd2 = math.random(1,100)
else
end
–Creates a display message on screen with two generated numbers
local mtext1= display.newText("The first generated number is: "…trnd1,500,400, native.systemFont, 40)
local mtext= display.newText("The second generated number is: "…trnd2,500,500, native.systemFont, 40)
–When RIGHT mouse button is clicked, clears the random values generated
elseif event.isSecondaryButtonDown then
mtext1:removeSelf()
mtext1=nil
mtext:removeSelf()
mtext=nil
end
end
– Add the mouse event listener.
Runtime:addEventListener( “mouse”, onMouseEvent )