Page 1 of 1

Waiting for a line then continuing

Posted: Thu Jan 24, 2019 8:25 pm
by quentinnuk
I have a button that I am trying to develop to find a way through a maze in order to find a treasure in the centre.

The maze has 11 levels which are randomly interconnected each reset of the mud. You cannot map the maze with objects.

My simplistic approach this is to generate random directions and keep firing them at the Mud until I stumble on the treasure but I only want to send one direction per input turn. So what I want to do is something like this in pseudo code (Im not knowledgable of Lua):

Code: Select all

local commands = {"sw", "s", "se", "ne"} -- the only valid directions in the mud
repeat
	local which = math.random(#commands)
	if line="*" then send(commands[which]) -- the command prompt on the mud is "*" 
until selectString("Treasure",1)~=-1 -- im looking for treasure
send("get treasure") 
How is the best way to do something like this, and if it gets into an infinite loop (because the treasure is not there), how do you stop it?

Thanks!