However, I created a bug, and now I get a error at line 62…
If someone can figure out why, it will be greatly appriciates.
--Note to self.
--TJ, YOU FOOL, you aren't making this game very modular with other maps!
--Fix it, and dont make any more map-related functions till you fix it!
-- Define Stuff.
local playerName = "Steve"
local xpGained = 0
local xpLevel = 0
local inventory = {"nil", "nil", "nil", "nil", "nil"}
local weapon = "nil"
local health = 20
local hunger = 20
local armor = 0
local damage = 1,5
-- testMap1.
local testMap1 = {"[]", "[]", "[]", " ", " ",
" ", " ", "##", " ", "[]"}
-- testMap1Props
local testMap1Props = {"s", "s", "s", "a", "a",
"a", "a", "a", "a", "s"}
-- loads a map
function loadMap(mapProps)
local loadedMap = mapProps
end
function SetPlayerPos(spot)
loadedMap[spot] = "##"
end
-- Check location function, checks for players current postition -- in the map.
-- Will probaly change when the way maps work change.
function checkPlayerCoords()
for i = 1, 10 do
f = loadedMap[i]
if f == "##" then
return(f)
end
end
end
-- Movement Function.
function movePlayer(direction)
spot = checkPlayerCoords()
setPlayerPos(spot)
end
-- Prints a Map
function printMap()
for i = 1, 10 do
term.write("" ..loadedMap[i])
if i == 5 then
print("")
end
end
end
-- Update tick functions, Oh gawd, here is where the fun part starts.
function waitOs()
os.startTimer(0.2)
event, t, s = os.pullEvent()
if event == "mouse_click" then
local mouseX = t
local mouseY = s
os.pullEvent("timer")
elseif event == "key" then
local pressedKey = t
print("" ..pressedKey)
if pressedKey == 200 then
movePlayer(up)
elseif pressedKey == 203 then
movePlayer(left)
elseif pressedKey == 208 then
movePlayer(down)
elseif pressedKey == 205 then
movePlayer(right)
end
os.pullEvent("timer")
elseif event == "timer" then
print("TIME!")
end
waitOs()
end
-- Function for middlePrinting, as many suggested...
w, h = term.getSize()
function centerPrint(y, text)
term.setCursorPos(w/2 - #text/2, y)
write(text)
end
-- Startup Stuff
local gotPressKeyStartScreen
function startScreenVisual()
term.clear()
centerPrint(h/2-2, "R P G G A M E")
while true do
centerPrint(h/2, "P R E S S A N Y K E Y")
centerPrint(h/2+1, "T O C O N T I N U E")
os.startTimer(1)
event, l = os.pullEvent()
if event == "key" then
temporary()
break
end
term.clear()
centerPrint(h/2-2, "R P G G A M E")
os.startTimer(1)
event, l = os.pullEvent()
if event == "key" then
temporary()
break
end
end
end
function temporary()
term.clear()
centerPrint(h/2, "Do Stuff!")
end
loadMap(testMap1Props)
printMap()
checkPlayerCoords()
setPlayerPos(9)
loadMap()
printMap()
--waitOs()
--startScreenVisual()