Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Trouble with variables across two triggers with variables...

Trouble with variables across two triggers with variables...

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


Posted by Sabach   (3 posts)  Bio
Date Fri 27 Dec 2013 12:30 AM (UTC)
Message
I tried to search the forum and watched the video on variables from Mr. Gammon. I still didn't figure it out, so I'm going to beg for help now...

I'm trying to use the mushclient variables in lua scripts. As I got started on some simpler things it worked great, but I'm having trouble with SetVariable changing quick enough to affect the rest of the script.

There is a spell on multimud.net called Sanctuary... it gives a message on successful completion and when it goes away. My plan was to have a isSanced variable and set it to 1 when the cast success message appears, and then check for success casting by casting the spell, waiting 5 seconds and seeing if the variable has changed and casting again. (I'm hoping I'm not dead in the water already). I printed out the @isSanced == 1 in the while comparison right before it, and got 1 == 0.

Thanks for any help in advance.

Michael Claar (Sabach)

Here is the code so far...

On the trigger You start glowing....
SetVariable ("isSanced", 1)

On the trigger *The white aura around your body fades.
require "wait"
print ("checkPoint 1")
SetVariable ("isSanced", 0)
wait.make ( function ()
print ("checkPoint 2")
print ("@isSanced == 0")
while @isSanced == false do
if @isSleeping == 0 then
print ("checkPoint 3")
if @currentMN > 100 then
print ("checkPoint 4")
Send "cast 'Sanctuary'"
end --if
end --if
wait.time (5)
end --while
end)


I see the checkPoints 1&2 and the 1 == 0 when I run it.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 27 Dec 2013 07:23 AM (UTC)
Message
Can you post the exact thing please?

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Sabach   (3 posts)  Bio
Date Reply #2 on Fri 27 Dec 2013 12:13 PM (UTC)

Amended on Thu 02 Jan 2014 08:48 PM (UTC) by Nick Gammon

Message
Sorry, this is my first time posting. If I didn't get this right, let me know and I'll try again.

Michael


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="ChargingTriggers"
   match="*The white aura around your body fades."
   send_to="12"
   sequence="100"
  >
  <send>print ("checkPoint 1")
require "wait"
SetVariable ("isSanced", 0)
wait.make ( function () 
  print ("checkPoint 2")
  print ("@isSanced == 0")
  while @isSanced == false do  
      if @isSleeping == 0 then
        print ("checkPoint 3")
        if @currentMN &gt; 100 then
          print ("checkPoint 4")   
          Send "cast 'Sanctuary'"
        end --if
      end --if
    wait.time (5) 
  end --while    
end)</send>
  </trigger>
</triggers>


<triggers>
  <trigger
   enabled="y"
   group="ChargingTriggers"
   match="*You start glowing."
   send_to="12"
   sequence="100"
  >
  <send>SetVariable ("isSanced", 1)</send>
  </trigger>
</triggers>


Adding the variable too...


<variables>
  <variable name="isSanced">0</variable>
</variables>


[EDIT] Code tags added.
Top

Posted by Ayon   (6 posts)  Bio
Date Reply #3 on Fri 27 Dec 2013 08:00 PM (UTC)
Message
Having not any experience with your MUD, I would think you are going about this a little bit backwards.

My first question is: Is there a failure message? That would be more interesting. You as a person are interested in being sanced, but from a computer perspective, it only needs to do something in two instances:

1) When you see the message: ^\s*The white aura around your body fades\.$
2) When you see a message like: You fail to cast sanc! or something to that effect.

I would be a little wary here, because you are getting dangerously close to botting, but that is your decision, you should be sure to check the rules of your MUD before you do it.

You don't even need scripting. For this, just two triggers would do it.

Waiting doesn't really seem necessary, but this seems like something you could do with a timer.

Why not simply add a one off timer via scripting to check the variable?

Also, if you are going to be doing scripting, might as well do it from a script file and simply have your triggers/aliases call a script function.

The MUD maintains the state for you, and tells you, generally, when you are sanced and when you are not. So no need to maintain state yourself.

State being( a variable set to 1 or 0).

This all assumes that you get a non general cast failure message. You might simply get something like: Spell Failed.

In which case. You will need to maintain state. If that's the case, then I suggest your problem will actually be more complicated that you think it is. If the only spell you ever want to work this way is Sanc, then it's fine, but if you want to use this method with other spells. You will need to create a spell queue, and maintain and index pointing to which spell you are currently casting, and when you receive the general message (Spell Failed. or some such) you will need to know in what part of the spell queue you are at.

We would just need to know more information than you've given us to be able to really help. I think from seeing what you've posted so far, that you are looking at it from the wrong direction. But only if you get a specific spell failure message.

I could be totally off though.
Top

Posted by Sabach   (3 posts)  Bio
Date Reply #4 on Fri 27 Dec 2013 08:59 PM (UTC)
Message
You asked for more information, so I'll try to paint the picture a little clearer...

Yes it is at the least a type of botting I'm aiming for, and yes it is allowed in a couple circumstances. A fuller picture is that we have a wand charging system where wizards work away casting the same spell over and over to achieve improve the quality of the wands. I made scripts that repeat casts on a variety of circumstances including time until tick, how much mana/move I have left. (Move can be used to increase the mana). It keeps count of the charges until it receives the desired maximum. All of that works fine, but there are three spells I also need to be able to cast up while the other system is running. (Food&Water, rest, and sanctuary). These three keep me alive and healthy, and they all have different lengths and times they are running.

The reason I wanted to script it instead of the timer, is I am often sleeping when the spell is ready, or maybe low on mana due to the charging of the wands. So my theory was wait to see if I'm sleeping or have enough mana, then when the statics were right, cast the spells.

I haven't learned lua at all yet really. I need to look up its functions/subroutines. I'm hoping the easiest answer is I can use the script file and then use lua variables for the answer.

To answer a question I think I missed... Yes there is error messages on fail, but different ones depending on why. I'd bet 7 to 10 possibilities, but I've never counted them.

I hope this cleared up the issue rather than muddying it more. I was trying in the first messages to stay to the most relevant parts.

Sabach
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 02 Jan 2014 08:52 PM (UTC)
Message

SetVariable ("isSanced", 0)
wait.make ( function () 
  print ("checkPoint 2")
  print ("@isSanced == 0")
  while @isSanced == false do  
...


The first thing that hits me is this.

Variables like @isSanced are expanded once, when the trigger is started. They won't change during execution. You are better off changing it, for example, to:


  while GetVariable ("isSanced") == "false" do  


Or better still use Lua variables and not MUSHclient variables for a variable inside a loop like that.

eg.


local isSanced = false
wait.make ( function () 
  print ("checkPoint 2")
  while not isSanced do  


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 02 Jan 2014 08:54 PM (UTC)
Message
Oh, OK I see you are setting the variable elsewhere. Stick with the MUSHclient variables, but use GetVariable to check it.

Also note that "false" and "0" are not the same in Lua.

If you are setting a variable to 1, test it for 1.

In fact, MUSHclient variables are strings, so if you set it to 1, you have to test for "1" which is also not the same as 1 (one is a number, one is a string).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


25,354 views.

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

Go to topic:           Search the forum


[Go to top] top

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