This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Micheal Pearce's profile picture

game bugs

Started by Micheal Pearce, 27 June 2013 - 11:39 PM
Micheal Pearce #1
Posted 28 June 2013 - 01:39 AM
so I've been trying to make a game like dig'n'rig its been going good so far but I've hit some bugs that i can't seem the resolve so I've come to you guys to see if you could help me here my code, and the two main bugs I've seen so far are 1: digging down after level 5 doesn't work 2: after you've dug one block and you reloaded the world you can not move past this one point


startlevels=15
Pmoney = 0
start = "true"
newworld = "true"
health = 100
armour = 0
score = 0
pX = 1
pY = 4
Ey = 2
Ex = 4
My = 0
Mx = 0
root = "SP_miner/worlds/"
install = fs.isDir("SP_miner")
if install == false then
  fs.makeDir("SP_miner")
  fs.makeDir("SP_miner/worlds")
end
function main()
term.clear()
startscreen()
running = true
while running do
term.clear()
term.setCursorPos(1,1)
drawworld()
drawHUD()
drawplayer()
mainupdate()
sleep(.1)
end
end
function rore()
term.setTextColor(colors.white)
local c = 4
if c == 4 then
   ore = math.random(1,3)
   My = math.random(1,16)
   Mx = math.random(1,51)
   term.setCursorPos(Mx,My)
   if ore == 1 then
	 write("c")
   elseif ore == 2 then
	 write("i")
   elseif ore == 3 then
	 write("t")
   end
end
end
function gameover()
running = false
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(51/3+4,19/2)
term.setTextColor(colors.red)
write("Game Over")
term.setCursorPos(51/3+5,19/2+1)
term.setTextColor(colors.white)
write("Score:"..score)
term.setCursorPos(1,19)
write("A game made by SteamTekk")
end
function mainupdate()
if health == 0 then
gameover()
end
if Ey == pY and Ex == pX then
  if armour == 0 then
	health = health - 10
  else
	armour = armour - 10
  end
end
end
function drawenemy()
  local function update()
	local r = math.random(1,4)
	if r == 1 then
	  Ey = Ey + 1
	elseif r == 2 then
	  Ey = Ey - 1
	elseif r == 3 then
	  Ex = Ex + 1
	elseif r == 4 then
	  Ex = Ex - 1
	end
  end
  local function border()
	if Ey == 1 then
	  Ey = 2
	elseif Ey == 17 then
	  Ey = 16
	end
	if Ex == 0 then
	  Ex = 1
	elseif Ex == 52 then
	  Ex = 51
	end
  end
  term.setCursorPos(Ex,Ey)
  term.setTextColor(colors.red)
  term.setBackgroundColor(colors.gray)
  write("X")
  update()
  border()
end
function startscreen()
term.setBackgroundColor(colors.black)
term.clear()
local x = 51/2
local y = 19/2
term.setCursorPos(x-4,y-2)
term.setTextColor(colors.yellow)
write("|Miner|")
term.setCursorPos(x-4,y-3)
write("+-----+")
term.setCursorPos(x-4,y-1)
write("+-----+")
term.setCursorPos(x-2,y)
write("New")
term.setCursorPos(x-5,y+2)
write("load world")
term.setCursorPos(x-4,y+4)
write("quit game")
sscreen = true
while sscreen do
  event,button,X,Y = os.pullEvent("mouse_click")
  if button == 1 then
   if (X>= 23 and X <= 25) and Y == 9 then
	sscreen = false
	term.clear()
	term.setCursorPos(1,1)
	write("World Name: ")
	local wname = read()
	root = root..wname
	fs.makeDir(root)
	  elseif (X>= 20 and X <= 29) and Y == 11 then
	sscreen = false
	term.clear()
	loading = true
	while loading do
	term.clear()
	term.setTextColor(colors.yellow)
	term.setCursorPos(1,1)
	write("World Name: ")
	local wname = read()
	root = root..wname
	local t = fs.isDir(root)
	newworld = false
	if t == true then
	 loading = false
	else
	 term.setCursorPos(1,2)
	 term.setTextColor(colors.red)
	 write("World not real :(/>/>")
	 sleep(1)
	   end
	end
   elseif (X>= 21 and X <= 29) and Y == 13 then
	   sscreen = false
	term.clear()
	os.reboot()
   end
  end
end
end
function drawworld()
local function update()

end
if newworld == "true" then
local rootmap = root.."/levelmap"
level = fs.open(rootmap,"w")
for i = 1,15 do
  if i == 1 then
   level.writeLine("000000000000000000000000000000000000000000000000000")
  elseif i == 2 then
   level.writeLine("000000000000000000000000000000000000000000000000000")
  elseif i == 3 then
   level.writeLine("000000000000000000000000000000000000000000000000000")
  elseif i == 4 then
   level.writeLine("222255222222222222222222222222222222222222222222222")
  else
   level.writeLine("111111111111111111111111111111111111111111111111111")
  end
end
level.close()
newworld = false
else
local rootmap = root.."/levelmap"
level = fs.open(rootmap,"r")
	places = level.readAll()
level.close()
term.setCursorPos(1,2)
tostring(places)
for i = 1,#places do
  color = places:sub(i,i)
  if tostring(color) == "0" then
  term.setBackgroundColor(8)
  write(" ")
  elseif color == "2" then
  term.setBackgroundColor(colors.green)
  write(" ")
  elseif color == "1" then
  term.setBackgroundColor(colors.gray)
  write(" ")
  elseif color == "5" then
  term.setBackgroundColor(colors.black)
  write(" ")
  else
  write(color)
end
end
end
update()
end
function drawHUD()
local function update()
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(1,18)
  write("Health: "..health)
  term.setCursorPos(1,19)
  write("Armour: "..armour)
  term.setCursorPos(12,18)
  write("|")
  term.setCursorPos(12,19)
  write("|")
  term.setCursorPos(13,18)
  write("Level:"..pY-1)
  term.setCursorPos(13,19)
  write("money:$"..Pmoney)
end
term.setBackgroundColor(colors.yellow)
term.setCursorPos(1,17)
write("												   ")
term.setBackgroundColor(colors.lightGray)
term.setCursorPos(1,18)
write("												   ")
term.setCursorPos(1,19)
write("												   ")
term.setCursorPos(1,1)
term.setBackgroundColor(colors.yellow)
write("												   ")
term.setTextColor(colors.black)
term.setCursorPos(1,1)
write("Miner			   WASD to move arrow keys to mine")
update()
end
function drawplayer()
local function DigBlock(way)
local levelmap2 = root.."/levelmap"
local level = fs.open(levelmap2,"r")
wholething = level.readAll()
level.close()
local level = fs.open(levelmap2,"w")
if way == "up" then

elseif way == "down" then
  local y = pY - 1
  local minus = 51 * y + pX + 4
  for i = 1,#wholething do
   term.setCursorPos(1,1)
   block = wholething:sub(i,i)
   if i == minus then
	level.write("5")
   else
	level.write(block)
   end
  end
elseif way == "left" then

elseif way == "right" then

end
level.close()
end
local function pbackground()
local levelmap2 = root.."/levelmap"
local level = fs.open(levelmap2,"r")
for i = 1,pY-1 do
  colorrow = level.readLine()
end
level.close()
for i = 1,pX do
  colornum = colorrow:sub(i,i)
end
if colornum == "0" then
  term.setBackgroundColor(colors.lightBlue)
elseif colornum == "5" then
  term.setBackgroundColor(colors.black)
end
end
local function update()
   pbackground()
   p1,p2 = os.pullEvent()
   if p1 == "timer" and p2 == timerID then
	 timerID = os.startTimer(.5)  
   elseif p1 == "key" then
	 if p2 == 17 then
	pY = pY - 1
  elseif p2 == 31 then
	pY = pY + 1
	 elseif p2 == 32 then
	pX = pX + 1
	 elseif p2 == 30 then
	pX = pX - 1
  elseif p2 == 200 then
  DigBlock("up")
  elseif p2 == 208 then
  DigBlock("down")
  elseif p2 == 205 then
  DigBlock("right")
  elseif p2 == 203 then
  DigBlock("left")
	 end
   end
end
local function border()
   local function wallborder()
	-- to get the block under player
local levelmap2 = root.."/levelmap"
local level = fs.open(levelmap2,"r")
for i = 1,pY-1 do
  colorrow = level.readLine()
end
for i = 1,pX do
  colornum = colorrow:sub(i,i)
end
if colornum == "0" then

elseif colornum == "5" then

else
  pY = pY - 1
end
  level.close()
  --end block under player
  --block above player
local levelmap2 = root.."/levelmap"
local level = fs.open(levelmap2,"r")
for i = 1,pY-1 do
  colorrow = level.readLine()
end
for i = 1,pX do
  colornum = colorrow:sub(i,i)
end
if colornum == "0" then

elseif colornum == "5" then

else
  pY = pY + 1
end
level.close()
  --end above player
  -- blocks to the left of player
  local levelmap2 = root.."/levelmap"
local level = fs.open(levelmap2,"r")
for i = 1,pY do
  colorrow = level.readLine()
end
for i = 1,pX-1 do
  colornum = colorrow:sub(i,i)
end
if colornum == "0" then

elseif colornum == "5" then

else
  pX = pX + 1
end
  level.close()
  --end blocks left
  -- blocks right of player
local levelmap2 = root.."/levelmap"
local level = fs.open(levelmap2,"r")
for i = 1,pY do
  colorrow = level.readLine()
end
for i = 1,pX+1 do
  colornum = colorrow:sub(i,i)
end
if colornum == "0" then

elseif colornum == "5" then

else
  pX = pX - 1
end
  -- end blocks right of player
	level.close()
   end
   wallborder()
   if pY == 1 then
	 pY = 2
   elseif pY == 17 then
	 pY = 16
   elseif pY == 3 then
	 pY = 4
   end
   if pX == 0 then
	 pX = 1
   elseif pX == 52 then
	 pX = 51
   end
end
pbackground()
term.setTextColor(colors.white)
term.setCursorPos(pX,pY)
write("X")
timerID = os.startTimer(.5)
update()
border()
end
main()
Zudo #2
Posted 28 June 2013 - 02:45 AM
What happens on these errors? Does it crash? If so, what does it say?
Micheal Pearce #3
Posted 28 June 2013 - 12:32 PM
What happens on these errors? Does it crash? If so, what does it say?
it doesn't crash the game breaks on the first bug you break thought the borders and on the second bug you can move past a point on the map