Posted 05 March 2012 - 02:45 AM
Im making a program and when i try to run it, i get a random number (17.)
Heres my code:
Heres my code:
selection = 1;
maxhealth = 20;
health = 20;
x = 0;
z = 0;
function drawMenu()
term.clear()
term.setCursorPos(1,1)
local function cPrint(text)
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
cPrint("Minecraft")
local function cPrint(text)
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
cPrint("")
local function cPrint(text)
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
if selection == 1 then
cPrint("[ Singleplayer ]")
else
cPrint("Singleplayer")
end
local function cPrint(text)
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
if selection == 2 then
cPrint("[ Quit Game ]")
else
cPrint("Quit Game")
end
end
while true do
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then
if selection > 1 then
selection = selection - 1
drawMenu()
end
elseif key == 31 or key == 208 then
if selection < 2 then
selection = selection + 1
drawMenu()
end
elseif key == 28 then
if selection == 2 then -- quit
os.shutdown()
end
break
end
end
function game()
term.clear()
term.setCursorPos(1,1)
print("HP: " ..health.. "/" ..maxhealth.. " X: " ..x.. " Z: " ..z)
end
game()
while true do
local e,key = os.pullEvent( "key" )
if key == 17
x = x - 1
game()
elseif key == 31
x = x + 1
game()
elseif key == 57 then
z = z + 1
wait(0.1)
z = z + 1
wait(0.1)
z = z - 1
wait(0.1)
z = z - 1
game()
end
end