[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Someone help me please

Someone help me please

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by Curious2   (47 posts)  [Biography] bio
Date Wed 04 Feb 2009 09:35 PM (UTC)

Amended on Thu 05 Feb 2009 02:35 AM (UTC) by Nick Gammon

Message
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.
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #1 on Wed 04 Feb 2009 10:36 PM (UTC)

Amended on Wed 04 Feb 2009 10:38 PM (UTC) by WillFa

Message
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,
[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #2 on Wed 04 Feb 2009 11:49 PM (UTC)
Message
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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #3 on Wed 04 Feb 2009 11:51 PM (UTC)
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #4 on Thu 05 Feb 2009 01:06 AM (UTC)
Message
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.
[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #5 on Thu 05 Feb 2009 01:21 AM (UTC)

Amended on Thu 05 Feb 2009 01:24 AM (UTC) by Curious2

Message
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?
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #6 on Thu 05 Feb 2009 01:40 AM (UTC)
Message
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)



[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #7 on Thu 05 Feb 2009 01:45 AM (UTC)
Message
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.

[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #8 on Thu 05 Feb 2009 02:30 AM (UTC)
Message
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


[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #9 on Thu 05 Feb 2009 02:33 AM (UTC)

Amended on Thu 05 Feb 2009 02:43 AM (UTC) by Curious2

Message
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?
[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #10 on Thu 05 Feb 2009 02:38 AM (UTC)
Message
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.
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #11 on Thu 05 Feb 2009 02:44 AM (UTC)

Amended on Thu 05 Feb 2009 02:47 AM (UTC) by WillFa

Message
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.

[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Thu 05 Feb 2009 02:48 AM (UTC)
Message
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?


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #13 on Thu 05 Feb 2009 02:50 AM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #14 on Thu 05 Feb 2009 02:50 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


57,071 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]