Someone help me please

Posted by Curious2 on Wed 04 Feb 2009 09:35 PM — 24 posts, 96,016 views.

#0
I can't get this to work. I'm trying to create a defup routine. Now the real problem is I am so used to zmud type of scripting and it has me all confused. I usually just create a second trigger or something. But I would like to figure out how to do this with a coroutine.


function defup.eq()
  -- check if able
  if defing.try or
    not balance.eq or
    cures.general.paused then
    return
  end -- can't do it yet
  -- check defenses
  for _, v in ipairs(defing.eqdefs) do
    if not defense[v.name] then
      SendImmediate(v.command)
      defing.try = true
      return
    end
  end
  EnableTrigger("eqDefup", false)
end -- function defup


This has to wait for "You have recovered equilibrium." from the mud.

It will send the first one but then just stops working even after I received the equilibrium message. I didn't want to just stick it in my normal eq trigger because I don't want it running the function every time I get eq. I only want this function to be called during the defup routine. So I created two eq recover triggers and just enable and disable the one. I have it as a lower priority and keep evaluating.

Am I doing it wrong or what? Each time I receive "You have recovered equilibrium" I need it to call that function until all the defenses are up. It's just not working.
Amended on Thu 05 Feb 2009 02:35 AM by Nick Gammon
USA #1
Try this out. I haven't tested this, so it may need tweaking. The concept works tho


require "wait"

function defupAlias (a, l, w)
  wait.make(function ()
    for _,v in ipairs (defining.eqdefs) do
      if not defense[v.name] then
        SendImmediate(v.command)
        wait.match("You have recovered equilibrium.")
      end  --if
    end  --for
  end)  --function in wait.make
end -- function for alias to call
  


You don't need a separate equilibrium trigger using this,
Amended on Wed 04 Feb 2009 10:38 PM by WillFa
#2
Ugh how do I test this stuff offline??

Run-time error
Plugin: FullSystem (called from world: Achaea)
Immediate execution
C:\Program Files\MUSHclient\lua\wait.lua:150: Not connected to MUD
stack traceback:
[C]: in function 'assert'
C:\Program Files\MUSHclient\lua\wait.lua:150: in function 'make'
[string "Plugin"]:1370: in function 'eq'
[string "Alias: "]:2: in main chunk


I can't stand having to use plugins for everything either.
USA #3
There's a MUD text simulation feature in the client somewhere, although since I don't have it in front of me I can't point you straight to it.
USA #4
You're getting the error "Not connected to MUD" Are you connected and online?

And you don't have to use a plugin for everything, there is the main script file (ctrl+shift+6) that you can write to and recompile a bit more easily.


The Mud Simulation text is CTRL+SHIFT+F12.
#5
Obviously I am not connected to the MUD. It's why I asked how I could test offline. Apparently you have to be connected to use wait...

Also I have to use a plugin so I can use ATCP otherwise I have to do retarded stuff like passing crap back and forth with aliases. I'd like to just be able to have everything in one script file. However, you can only do certain things with plugins. It's a pain to edit then reload then edit then reload.

I looked at the wait.lua. Basically that just makes a temporary trigger?
Amended on Thu 05 Feb 2009 01:24 AM by Curious2
USA #6
Basically. but a little more.

If you want to tweak wait.lua to allow offline testing,

comment out line 150: assert(not(GetInfo(106) or GetInfo(107)...

add the timer_flag.ActiveWhenClosed to the flags in the two AddTimer() calls (in the regexp and time functions)



#7
Ok I took out the part that requires you to be connected in the wait.lua so I could test this.

I don't like how it works. It just creates a temp trigger which overrides my normal eq recovery trigger. Then it has to fire an additional time before my normal eq recovery trigger will work again.


You have recovered equilibrium.
touch mindseye
You have recovered equilibrium.
alertness on
You have recovered equilibrium.
deathsight
You have recovered equilibrium.
hypersight on
You have recovered equilibrium.
curseward
You have recovered equilibrium.
selfishness
You have recovered equilibrium.
#######################EQUILIBRIUM################ <-- normal trigger substituted and colored.

USA #8
Try subtituting this funcion in wait.lua instead



function regexp (regexp, timeout, KeepEval, Seq)
  local ke, seq = 0, tonumber(seq) or 100
  if KeepEval then ke = trigger_flag.KeepEvaluating end
  local id = "wait_trigger_" .. GetUniqueNumber ()
  threads [id] = assert (coroutine.running (), "Must be in coroutine")

  check (AddTriggerEx (id, regexp, 
            "-- added by wait.regexp",  
            trigger_flag.Enabled + trigger_flag.RegularExpression + 
            trigger_flag.Temporary + trigger_flag.Replace +
            trigger_flag.OneShot + ke,
            custom_colour.NoChange, 
            0, "",  -- wildcard number, sound file name
            "wait.trigger_resume", 
            12, seq))  -- send to script (in case we have to delete the timer)
 
  -- if timeout specified, also add a timer
  if timeout and timeout > 0 then
    local hours, minutes, seconds = convert_seconds (timeout)

    -- if timer fires, it deletes this trigger
    check (AddTimer (id, hours, minutes, seconds, 
                   "DeleteTrigger ('" .. id .. "')",
                   timer_flag.Enabled + timer_flag.OneShot + 
                   timer_flag.Temporary + timer_flag.ActiveWhenClosed + timer_flag.Replace, 
                   "wait.timer_resume"))

    check (SetTimerOption (id, "send_to", "12"))  -- send to script

    -- if trigger fires, it should delete the timer we just added
    check (SetTriggerOption (id, "send", "DeleteTimer ('" .. id .. "')"))  

  end -- if having a timeout

  return coroutine.yield ()  -- return line, wildcards
end -- function regexp 



And then in your plugin...


require "wait"

function defupAlias (a, l, w)
  wait.make(function ()
    for _,v in ipairs (defining.eqdefs) do
      if not defense[v.name] then
        SendImmediate(v.command)
        wait.match("You have recovered equilibrium.", nil, true, 50)
      end  --if
    end  --for
  end)  --function in wait.make
end -- function for alias to call


#9
Well ok back to the orginal plan...

Why doesn't this trigger fire?

<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^You have recovered equilibrium\.$"
name="eqDefup"
regexp="y"
send_to="12"
sequence="50"
>
<send>print("FIRED")
defup.eq()</send>
</trigger>
</triggers>

The main trigger is sequence 100. This trigger won't fire when I test it. It should print FIRED but it doesn't. My main trigger substitutes the line so it is firing but this one isn't. If I disable my main trigger, then this one fires. I'm confused.

Edit: Doesn't this forum have a code tag to keep the spacing?
Amended on Thu 05 Feb 2009 02:43 AM by Curious2
#10
Will that doesn't work right anyway. If you notice where I tested it, you can see it just ran through the whole list. It needs to return when it sends the command. If it fails to put up the defense, then it should try again and THEN move to the next one.
USA #11
The original doesn't work because you never set defining.try to false anywhere, so that initial if ... then return end always is true on subsequent calls.


The second one with the print("FIRED") in it should be matching, just that the keep evaluating and the subsequent omit eats the print as well as the line. (sendto 14 instead of 12 (script after omit)). Hit CTRL+ALT+T to turn tracing on to see if it actually matches.



Edit: Yes it does. You need to click the checkbox for Forum Codes below the input area and above the save changes button.

Amended on Thu 05 Feb 2009 02:47 AM by WillFa
Australia Forum Administrator #12
Quote:

I looked at the wait.lua. Basically that just makes a temporary trigger?


It makes a temporary trigger and/or timer, depending if you are waiting on a time, an incoming string, or both.

If you make a trigger using wait.lua and also have an identical trigger in your world file, naturally things are going to get confusing. Don't do it that way. Make up your mind if you want to wait in the coroutine, and remove the trigger from the main file, or use the "two trigger" approach which you said you used to do in zMUD.

You can use Simulate to pretend stuff came from the MUD:

http://www.gammon.com.au/scripts/doc.php?function=Simulate

As for reloading plugins, here is one idea:

http://www.gammon.com.au/forum/bbshowpost.php?id=8767

That has an option to reload all plugins.

When I was doing extensive work on plugins I made myself a "reload plugin" alias (rl) - so after editing the plugin in my text editor, I just typed "rl" to get the new version. This is hardly a big overhead.

Just add the alias below, and then substitute the plugin ID (from the top of the plugin) and the correct plugin file name, in case it needs to load it from disk.

The alias first attempts to reload the plugin (the ReloadPlugin line) and if that fails (eg. because of a compile error) it load it from disk using LoadPlugin.


<aliases>
  <alias
   match="rl"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

if ReloadPlugin ("26f4c7c7ca9f47d3ec4b072c") == error_code.eNoSuchPlugin then
  check (LoadPlugin ("/program files/mushclient/worlds/plugins/some_plugin.xml"))
end

Note "plugin *some_plugin * reloaded"

</send>
  </alias>
</aliases>



Quote:

My main trigger substitutes the line so it is firing but this one isn't.


What do you mean by this?

#13
Yes I did. I set it to false in the eq trigger.

Trace doesn't tell me anything at all except this...

TRACE: Executing Plugin ATCP script "OnPluginPacketReceived"
#######################EQUILIBRIUM#######################

The trigger will not fire. My main eq recovery trigger fired though as you can see.
Australia Forum Administrator #14
Quote:

Doesn't this forum have a code tag to keep the spacing?


Yes, and I amended your first post to use it.

Just use [code] ... [/code] in your posting. If done on the initial post that automatically turns the forum codes checkbox on. If you are editing, check the "forum codes" checkbox if you have decided to add them later.
#15
Quote:
What do you mean by this?


I mean my main eq recovery trigger omits from output then prints something else. In this case the "#####EQUILIBRIUM#####" message so it is easy to see that it obviously fired. I put to print("FIRED") in the other one, but it never fires.
Australia Forum Administrator #16
See http://mushclient.com/faq point 51.

If any trigger does an omit from output, then any notes done in trigger "send to script" are also omitted. You need to make this one "send to script (after omit)".

So really, it fired, you just didn't see your note. The trace feature (game menu -> trace) would show that. Also check the fire count on the trigger itself.
#17
You need to check send to script after omit on both triggers even though one doesn't omit?

Also trace doesn't show me anything at all.
#18
Well that was the problem. I changed the other one to send to script after omit and it calls the function now. Finally! Something so simple took 3 hours to figure out. haha

By the way, thanks for the quick responses and the help!
Amended on Thu 05 Feb 2009 03:24 AM by Curious2
Australia Forum Administrator #19
Quote:

Also trace doesn't show me anything at all.


Well that is quite amusing, you must admit. :-)

The trace output is noted to the output window, and thus is also omitted.

I just wrote a small plugin that you can quickly install, that will redirect trace output to a notepad window, thus getting around that particular problem.

http://www.gammon.com.au/forum/?id=9217
Australia Forum Administrator #20
Quote:

You need to check send to script after omit on both triggers even though one doesn't omit?


Yes indeed. The line is omitted, and therefore the problem with notes still applies.
Australia Forum Administrator #21
Also see this for another plugin that shows trace output to a miniwindow: http://www.gammon.com.au/forum/?id=9218
#22
Ahhhh no wonder trace didn't show!! That made me laugh. That sneaky omit has gotten me a couple times now.

By the way, I tried to import a file and there was an error and this is what showed in the window...

&#26956;&#25966;&#8224;&#8224;&#14905;&#20512;&#30060;&#26983;&#8302;&#28526;&#8308;&#30821;&#25968;&#29795;&#25701;&#26656;&#29285;&#11877;&#21792;&#25971;&#17952;&#27753;&#8293;&#15917;&#20512;&#30060;&#26983;&#29550;&#29728;&#8303;&#28524;&#25697;&#28704;&#30060;&#26983;&#29550;&#10272;&#29296;&#25199;&#25964;&#8301;&#28265;&#29728;&#26984;&#8307;&#26982;&#25964;&#3369;

Y


I'd really like to learn that language but I am having a hard enough time trying to learn all these programming languages at my age. I don't know how you guys can remember them all.

Edit: Well it won't show up but it is all Chinese.
Amended on Thu 05 Feb 2009 07:19 AM by Curious2
Australia Forum Administrator #23
I presume you aren't actually asking a question about that. :P

I want to also point out that if you install one of those tracing plugins, you can use TraceOut for debugging. If tracing is turned on, the message sent to TraceOut also appears. This lets you put debugging stuff in your scripts, and not have it show up, unless you need it (by turning Trace on).


http://www.gammon.com.au/scripts/doc.php?function=TraceOut