• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

102 Neutral

About arone8900

  • Rank
  1. Thank you, you sir are a god!!!!!!!!!
  2. apologies the <span> stuff was to colour the code to show which bits where relevant.
  3. Been re reading this code so many times and can't figure out the problem, been tearing my hair out, any suggestions/solutions would be greatly appreciated. Ignore the naff attempts at story writing its just filler till I get the engine working. I've highlighted the area I believe the problem is in. full code attatched Basically when location = location.exit.(N,S, E or W) is run its meant to change the players location to a different place, in the current location two of these exits lead back to the same place, these commands work, but when I type N or W it says "attempt to index global 'location' (a nil value)", now changing location = location.exit.W to location = clearing it works but if I did it this method then I would have to right masses of code I'm trying to shorten it so each location has a set of exit values which link up to a standard move function thus dramatically reducing code. I'm not being lazy I just want to get in the habit of writing concise readable code. In advance thanks for even reading this. relevant code: (Lua code) [source lang="plain"]--move standard function stmove() --standard functions if intAA == "N" then [color=#ff0000]location = location.exit.N[/color] elseif intAA == "E" then location = location.exit.E elseif intAA == "S" then location = location.exit.S elseif intAA == "W" then location = location.exit.W elseif intAA == "statcheck" then charsheet() elseif intAA == "showi" then Inv.display() elseif intAA == "help" then print(help()) else stmoveused = 0 end end --places oooooooo repeatr .exit = {N = , E = , S = , W = } = {name = "", Desc = ""} foresta = {name = "foresta", Desc = "you look around and you are in a dark forest, something is rustling North of you"} [color=#ff0000]foresta.exit = { N = forestsnork, E = foresta, S = foresta, W = clearing}[/color] function foresta.move() stmoveused = 1 stmove() if intAA == "examine forest" then print("\n".."you look around and see a sea of fir trees coating in small fern skirts, the sun looms \nhigh and the blossoming green of the leaves suggests the season to be early spring.") elseif intAA == "smell forest" then print("the smell of ferns and dry leaves freshens your senses") elseif stmoveused == 1 then _ = 4 else print("\n","unknown command") end end clearing = {name = "clearing", Desc = "you enter a small clearing, and find a small health potion"} clearing.exit = {N = foresta, E = foresta, S = foresta, W = foresta} function clearing.move() stmoveused = 1 stmove() if intAA == "examine clearing" then print("\n" .. "you see nothing of note") elseif intAA == "smell forest" then print("still smells like the forest") elseif stmoveused == 1 then _ = 4 else print("\n" .. "unknown command") end end forestsnork = {name = "forestsnork", Desc = "A wild snork sharply shoots its eye's towards you, its looks angered by your presence" } forestsnork.exit = {N = temple, E = forestsnork, S = foresta, W = forestsnork} function forestsnork.move() stmoveused = 1 stmove() if intAA == "examine snork" then print("\n" .. "a pudgy little creature looks at you angryly") elseif intAA == "smell forest" then print("\n" .. "smells like snork poo") elseif stmoveused == 1 then _ = 4 else print("\n" .. "unknown command") end end temple = {name ="temple", Desc = "you have found the holy grail well done, you may now win",} print ("\n".."welcome to the land of spud you are an adventurer") [color=#ff0000]location = foresta[/color] stmoveused = 1 n = 1 Wmonster = snork Damage = 1 monDamage = 1 repeat [color=#ff0000]print (location.Desc)[/color] [color=#ff0000]intAA = io.read() location.move()[/color] if Warrior.H <= 0 then print("sadly you have died") break end until location == temple[/source] [url="http://codeviewer.org/view/code:2785"]http://codeviewer.org/view/code:2785[/url]
  • Advertisement