link between actions and triggers

Post Reply
dano
Posts: 2
Joined: Sun Oct 04, 2020 2:17 am

link between actions and triggers

Post by dano »

Hello,

I am new to Mudlet and have been unsuccessful trying to solve a task I'd like to perform.

What I would like to have is an action that moves me around a fixed path one time - when I type search for example. However, if, while moving from location to location in that path, a specific string is encountered (item, npc, whatever), I want the action to terminate the loop leaving me in the location where the item was found. It seems to me this would require communication between triggers and actions. Or, perhaps, there is another way and I just haven't found it yet. A simplified version of what I envision would be an action along the lines of:

Code: Select all

path = { "n","n","n","e","e","e", "s","s","s","w","w","w" }

for step = 1, #path do
  if ThingFound == true then
    break
  else
    send( path[step] )
  end
end
I know a trigger can sense the text via the output but how can the action be made aware of this discovery causing it to break the loop stopping the moves.

Thanks in advance for any assistance anyone can provide.

Dano.

User avatar
demonnic
Posts: 680
Joined: Sat Dec 05, 2009 3:19 pm

Re: link between actions and triggers

Post by demonnic »

Break it into single steps. Have the function take a step, then a trigger for your prompt which checks if you're walking somewhere, and if you found the thing. If you're walking somewhere and you have not found the thing, take the next step. Simple example for demonstration below
Code: [show] | [select all] lua
--script, holds the function
function doNextWalk()
  if #autowalkPath == 0 then 
    autowalking = false
    echo("We have arrived at the end of the path, walking off")
    return 
  end
  local nextDir = table.remove(autowalkPath, 1)
  send(nextDir)
end

--alias to start walking, whatever pattern you like
autowalking = true
thingfound = false
autowalkPath = { "n","n","n","e","e","e", "s","s","s","w","w","w" }
doNextWalk()

--alias to stop walking
autowalking = false
autowalkPath = {}


--trigger, fires on an arrival line or your prompt
if autowalking then
  if thingfound then
    echo("We found the thing, stopping\n")
  else
    doNextWalk()
  end
end

--and a trigger which fires when you found the thing and sets thingfound = true
[code]

dano
Posts: 2
Joined: Sun Oct 04, 2020 2:17 am

Re: link between actions and triggers

Post by dano »

Demonnic,

That does exactly what I was looking for. Thank you!

Dano.

Post Reply