Random direction

edited June 2019 in Mechanic's Corner
Literally random thing I made as a setup for something else. It makes you walk in a random direction, and attempts to choose a different random direction if there are icewalls/locked doors/blocking, etc.

function DirectionCheck()
dirName = {}<br>&nbsp; &nbsp;for i,v in pairs(gmcp.Room.Info.exits) do<br>&nbsp; &nbsp; &nbsp; &nbsp; dirName[#dirName+1]=i<br>&nbsp; &nbsp;end<br>randomWalk(true)<br>end
<br>function randomWalk(escapeAttempt)<br>&nbsp; &nbsp;if escapeAttempt then<br>&nbsp; &nbsp; &nbsp; if dirName[1] ~= nil then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;currentDir = dirName[math.random(1,table.size(dirName))]
         if currentDir ~= "x" then
	    send(currentDir)
	 else
	     for i=1,#dirName do
    	         if dirName[i] == "x" then 
       		    table.remove(dirName,i)
    	         end
	     end
	     escapeAttempt(true)
	 end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo("Oh no! We're trapped!")<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp;end<br>end

Trigger(exits blocked):

for i=1,#dirName do
    if dirName[i] == currentDir then 
       table.remove(dirName,i)
    end
end
randomWalk(true)
<p></p>

(I use a function to do the echo part, this was just to make it more obvious what it does)

Looking for any suggestions on how to expand on this.

Edit: I'm capturing special exits with this(the "x") which I want to do, I'm just not sure yet what I want to do with the x. So I added a part to remove it for now.

Comments

  • I like this and may steal it, thanks!

    You could extend it to try and walk if you're free, leap or tumble if not.
  • Dys said:
    I like this and may steal it, thanks!

    You could extend it to try and walk if you're free, leap or tumble if not.
    That's the idea, yeah, eventually.
Sign In or Register to comment.