Author Topic: Need help with a lua code  (Read 2141 times)

That's my point, it shouldn't "goto w" at all, it should just restart the loop, asking the player to attack again. (I assume you have other actions planned aside from "attack", otherwise asking the player to type it is pointless, and would be annoying in the case of a typo.)

Also, why do you have multiple loops? Your game should be running under one loop, calling multiple functions to do different tasks, such as going to the store, fighting a monster, etc.
Code: [Select]
-- variables in such
while true do
  -- walking around i suppose
  if iCanEncounterAMonster then
    approach(someRandomMonster)
  end
  if iCanGoToTheScore then
    gotoTheStore()
  end
end

That should be the extent of your program. Using gotos to hop to and from different loops is extremely bad logic.

That's the problem because if I have it running under one loop then i will have io.read() multiple times and the loop keeps going so I have to break the loop to continue story I need someone to help me with this

You should never, ever have to break the loop until the game ends. Literally every modern program that doesn't blow stuff runs under one, singular, loop. Chrome doesn't break the loop to open tabs in other processes, skype doesn't need to break the loop to call someone, sublime text doesn't need to break the loop to open a new project, and steam doesn't need to break the loop to install a new game.

There's no reason for you to need to break the loop to "continue the story".