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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Script format help please

Script format help please

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


Posted by David B   USA  (80 posts)  [Biography] bio
Date Fri 07 Mar 2003 11:51 AM (UTC)

Amended on Fri 07 Mar 2003 11:54 AM (UTC) by David B

Message
My trigger is based on my prompt line:
trigger: <(H|T|HT)>
Regular expression

Runs this subroutine:

sub DiscardQueue (name, line, wilds)
world.DiscardQueue
IF world.getvariable ("Sleeping") = "yes" then
world.send "rest"
end if
if world.getvariable ("Sleeping") = "no" then
end if
dim count
for count = 1 to 3
world.send "emote drinks soup"
next
world.send world.getvariable ("Sleeper")
end sub

(note: I do have the variable for when I sleep, and when I wakeup change the variable "Sleeping" when appropriate)

This doesn't quite work the way I thought it should work.

I was figuring it to do the if statements, then the dim then the last world.send. But it doesn't for some reason it does the dim first, then everything afterwards.

basically i want it to check to see if I am sleeping, if yes, then rest, drink soup 3 times, then sleep again.
if no then drink soup and sleep pillow.

Of course discarding the queue first regardless of what its supposed to be.

basically trigger looped myself because of my prompt.
I needed to test if it worked while I was sleeping. It didn't. So I changed world.send "drink soup" to world.send "emote drinks soup"
I had a world.note in there as well but for the reasoning I posted it up on the forum it wasn't needed. It was for testing pourposes.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 08 Mar 2003 08:45 PM (UTC)
Message
I don't know what you mean by "it does the dim first". Dim just declares a variable, and AFIK the dim statements should come at the start. It doesn't really "do" a DIM.

I don't see what this line does:

if world.getvariable ("Sleeping") = "no" then
end if

Why bother doing an IF if you don't do anything inside it?

Is this a typo? ...

world.send world.getvariable ("Sleeper")


The variable you were using before was "Sleeping" not "Sleeper".


- Nick Gammon

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

Posted by David B   USA  (80 posts)  [Biography] bio
Date Reply #2 on Sat 08 Mar 2003 11:01 PM (UTC)
Message
Ok. I see how you would be confused. I was originally going to do something else with the "no" statement but I changed my mind.

I dropped that.

What I mean is simply this. Originally I wanted it to set my speedwalk at whatever when the script is called. I.E. 6000ms or something.
Then once the counting script is completed, it set the speedwalk back to 0ms

Now, being a linear type of guy i figured. it would go through the script and no big deal, it sets the speed walk at 6000ms, does the counting part, then changes Speedwalk back to 0ms at the end, this way, I don't have to worry about changing the speedwalk delay whenever I want to use it.

This being the Logical assumption on how it works.

In reality, it does not work this way, at least when I tried it.

I set it up like this:

sub SpamCast(name, output, wilds)
world.setvariable "Sleeping", "no"
world.SpeedWalkDelay = 7000
world.colournote "yellow", "black", "My speedwalk delay has returned to: " & world.SpeedWalkDelay
dim count
for count = 1 to world.getvariable ("SpellCount")
world.queue "c " & world.getvariable("SpellName"), 0
next
world.send world.getvariable ("Sleeper")
world.send "inventory"
world.speedwalkdelay = 0
world.note "Speedwalk 0ms"
end sub

What happens is it sets the variable fine, it sets the speedwalk delay fine, world.notes me fine, then sets the speedwalk again at 0, and notes me again, THEN goes through the whole counting part of the script.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Wed 12 Mar 2003 05:18 AM (UTC)
Message
The speedwalk delay is a global thing, it doesn't remember the delay per queued command.

What you are doing is queuing a whole heap of things, and then, before it has a chance to do the queued things (which it will when the script exits) you have set the speedwalk delay back to zero, so they all get sent at once.

- Nick Gammon

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

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #4 on Wed 12 Mar 2003 07:50 AM (UTC)
Message
I think I know what you are trying to accomplish. I do the same thing often, though without using delays between commands, and here's what I use to do some tasks after the commands are executed...

You have a series of commands you want to send: command1, command2, command3. And you have a series of actions you want to perform after all the commands are done with: action1, action2, action3. This seems like a straightforward enough task - just have an alias call the script, have the script send the commands and then the actions. However, this won't work, since the actions will be performed before the commands have any chance of even leaving your computer. Thus, I do it in a different way - I add a fourth command (command4) into the series of them, that one is usually an emote. Then I add a trigger to match on that emote and call a script which will do: action1, action2, action3. Commands and actions are contained in different script routines, connected through a trigger by the last command in the series.

In your case, it could look like this (ignoring MUD-specific syntax):


<trigger
 name="finishSpamCast"
 enabled="y"
 match="You have emoted: SpamCast finished."
 script="FinishCast"
 sequence="100"
></trigger>


sub SpamCast(name, output, wilds)
  world.setvariable "Sleeping", "no"
  world.SpeedWalkDelay = 7000
  world.colournote "yellow", "black", "My speedwalk delay has returned to: " & world.SpeedWalkDelay
  dim count
  for count = 1 to world.getvariable ("SpellCount")
    world.queue "c " & world.getvariable("SpellName"), 0
  next
  world.send world.getvariable ("Sleeper")
  world.send "inventory"
  world.send "emote SpamCast finished" //this is 'command4'
end sub


sub FinishCast(name, output, wildcs)
  world.speedwalkdelay = 0
  world.note "Speedwalk 0ms"
end sub


[Go to top] top

Posted by David B   USA  (80 posts)  [Biography] bio
Date Reply #5 on Wed 12 Mar 2003 04:26 PM (UTC)
Message
Ok, I have another idea on how to do this.
What is in the queued command part I put in an if statement that is run everytime.

sub SpamCast(name, output, wilds)
world.setvariable "Sleeping", "no"
world.SpeedWalkDelay = 7000
world.colournote "yellow", "black", "My speedwalk delay has returned to: " & world.SpeedWalkDelay
dim count
for count = 1 to world.getvariable ("SpellCount")
world.queue "c " & world.getvariable("SpellName"), 0
if <myvariable> = <number> then
<set the speedwalkdelay to 0ms>
else
<set myvariable at what it is +1>
next
world.send world.getvariable ("Sleeper")
world.send "inventory"
end sub

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #6 on Wed 12 Mar 2003 08:05 PM (UTC)
Message
Umm. No... That just does the same thing as before, but in a different way. The thing you have to remember is that scripts are in the same 'thread' as your input. What I mean is that any commands it sends 'must' be delayed until the script itself ends. Example:

1. You type "cast light 5". i.e. cast light five times, not sure what syntax you are using here.
2. The script is called and does 'everything' you are telling it to, then exits.
3. The commands the 'script' sent are processed.

You are expecting it to do this:

1. You type "cast light 5".
2. Script sets speedwalk.
3. Script sends command.
4. Client executes command.
5. Script sends next command.
...
13. Script sets speedwalk back to normal and exits.

This 'would' work if the script ran seperate from the program, but it doesn't. Instead, everything the client normally does is suspended 'until' the script exits. You commands will never happen before the speedwalk delay is changed, since they never get sent until after the script has finished. You would need to do something more like this:

1. You type "cast light 5".
2. Script sets mushclient variables Spell = "light", Count = "1" and SpellEnd = "5", then enables a timer.
3. Timer calls a script which sends the cast command, then increases Count by one. If it is now greater than SpellEnd it disables the timer.
4. Timer calls a script ...

In other words, instead of using for-next, you build one. In this case, you can also set the delay with the timer length, instead of the speedwalk, but imho since the timer can't be set more accurate than 1 second intervals, it is a bit annoying. However, since your delay doesn't have to have millisecond precision, in this case it will work fine.
[Go to top] top

Posted by David B   USA  (80 posts)  [Biography] bio
Date Reply #7 on Thu 13 Mar 2003 03:47 AM (UTC)

Amended on Thu 13 Mar 2003 03:51 AM (UTC) by David B

Message
After thinking about it for a few minutes I think I understand why it doesn't and won't ever work.

The script is instantaneous. As soon as it it called it does all the meat within the subroutine right away. it doesn't wait for the queued commands to go through. The only way I could change that is too... Nevermind, I got it. Problem solved. Thanks a bunch

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Thu 13 Mar 2003 09:59 PM (UTC)
Message
Quote:

You commands will never happen before the speedwalk delay is changed, since they never get sent until after the script has finished.


Queued commands won't, you are right. "Immediate" commands (like world.note, world.send) are done during the script execution.

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


18,007 views.

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]