Code: Select all
if choice == 1 then
screen.print(200, 100, "1", red)
end
if choice == 2 then
screen.print(200, 100, "2", red)
end
if choice == 3 then
screen.print(200, 100, "3", red)
end
Code: Select all
checkcontrols()
Code: Select all
if choice == 1 then
screen.print(200, 100, "1", red)
end
if choice == 2 then
screen.print(200, 100, "2", red)
end
if choice == 3 then
screen.print(200, 100, "3", red)
end
Code: Select all
checkcontrols()
Ok,ty,but now it has an error script.lua:6: attempt to index global 'pad' <a nil value>Different55 wrote:This should be moved inside the loop, after the clear and before the flip.Code: Select all
if choice == 1 then screen.print(200, 100, "1", red) end if choice == 2 then screen.print(200, 100, "2", red) end if choice == 3 then screen.print(200, 100, "3", red) end
This should be added into the loop. It works wherever, really, but it would work best at the beginning of the loop, right after oldpad.Code: Select all
checkcontrols()
Code: Select all
-- My Second Lua Program
-- Author: Dragonxtamer596
red = Color.new(255, 0, 0)
if pad:start() and oldpad:start() ~= pad:start() then
choice = math.ceil(math.random(1, 3))
end
while true do
pad = Controls.read()
oldpad = Controls.read()
checkcontrols()
screen:clear()
if choice == 1 then
screen.print(200, 100, "1", red)
end
if choice == 2 then
screen.print(200, 100, "2", red)
end
if choice == 3 then
screen.print(200, 100, "3", red)
end
screen.flip()
screen.waitVblankStart()
end
Code: Select all
math.ceil(math.random(0, 3))
Code: Select all
math.floor(math.random(1, 4))
Code: Select all
math.randomseed(os.date("%S"))
Code: Select all
pad = Controls.read()
oldpad = Controls.read()
Code: Select all
oldpad = pad
pad = Controls.read()
Code: Select all
math.randomseed(os.date("%S"))
Code: Select all
math.randomseed(tonumber(os.date("%S")))
Opps forgot the s, print.smily("100,50,facepalm,red")qwikrazor87 wrote:Post what you wrote for math.randomseed.
Make sure your wrote the correct os.date argument.If that doesn't work then do this,Code: Select all
math.randomseed(os.date("%S"))
Code: Select all
math.randomseed(tonumber(os.date("%S")))
Code: Select all
-- My Second Lua Program
-- Author: Dragonxtamer596
red = Color.new(255, 0, 0)
math.randomseed(os.date("%S"))
while true do
oldpad = pad
pad = Controls.read()
checkcontrols()
screen:clear()
if pad:start() and oldpad:start() ~= pad:start() then
choice = math.ceil(math.random(1, 3))
end
if choice == 1 then
screen.print(200, 100, "1", red)
end
if choice == 2 then
screen.print(200, 100, "2", red)
end
if choice == 3 then
screen.print(200, 100, "3", red)
end
screen.flip()
screen.waitVblankStart()
end
Code: Select all
function checkcontrols()
--code here
end
while true do
checkcontrols()
--code here
end
Code: Select all
choice = math.ceil(math.random(0, 3))
Code: Select all
math.floor(math.random(1, 4))
Code: Select all
if pad:start() and not oldpad:start()then
--code here
end
IT WORKS!!!! YES, awsome!!!qwikrazor87 wrote:you didn't make the function checkcontrols()
you need to make it before you call it and I don't see it in your code.
Example:Also for choice you should change it toCode: Select all
function checkcontrols() --code here end while true do checkcontrols() --code here end
because your current code will only output 2 and 3.Code: Select all
choice = math.ceil(math.random(0, 3))
or you can doTo make your code less redundant you can do control arguments like thisCode: Select all
math.floor(math.random(1, 4))
Code: Select all
if pad:start() and not oldpad:start()then --code here end