Help - Search - Members - Calendar
Full Version: Flash Client - Programming A Delay
Achaea's Forums > Off-Topic > Tech Support > Client Help
Kazuya
One of the ideas I saw in the help section found in the flash client settings was adding a delay. I have experimented a little bit but cannot seem to get it to work. The page I am referencing is http://bc-dev.net/projects/fmud/fmud-scripting/ .

In the end, I would like to be able to use this delay feature to create an alias allowing me to be able to walk from one room to one multiple rooms away. Without the delay in sending directions, the server sends back a message telling you to slow down. Has anyone had any success using the delay method in Java?
Soludra
First: it's JavaSCIRPT (typo intentional); it and Java are entirely separate languages.

Second: what if you try something like this?

CODE
function walk(direction, number) {
  send(direction)
  AddTimer(1.5, "walk(" + direction + ", " + (number - 1) + ")")
}

walk(this[1], this[2])


Sort of pseudo-recursive, I suppose... O_o

EDIT: I haven't tested it, and I'm not planning on it, but I hope that works. smile.gif
Kazuya
I've tried to put in the code but am having some problems. Perhaps you could point where I'm going wrong...

Pattern: test(*,*)
Send: function walk(direction, number) {
send(direction);
AddTimer(1.5, "walk(" + direction + ", " + (number - 1) + ")");
}

walk(%1, %2)
Enabled: true
Script: true
RegExp: false
Priority: -1
Multi: false

When I try to enter in anything that starts out with "test", I am unable to hit enter. Maybe that is some clue as to what is going wrong.
Soludra
QUOTE (Kazuya @ Jun 14 2009, 07:32 PM) *
I've tried to put in the code but am having some problems. Perhaps you could point where I'm going wrong...

Pattern: test(*,*)
Send: function walk(direction, number) {
send(direction);
AddTimer(1.5, "walk(" + direction + ", " + (number - 1) + ")");
}

walk(%1, %2)
Enabled: true
Script: true
RegExp: false
Priority: -1
Multi: false

When I try to enter in anything that starts out with "test", I am unable to hit enter. Maybe that is some clue as to what is going wrong.


I believe you'll want this instead.

Pattern: dash * *
Send: function walk(direction, number) {
send(direction);
AddTimer(1.5, "walk(" + direction + ", " + (number - 1) + ")");
}

walk(this[1], this[2])
Enabled: true
Script: true
RegExp: false
Priority: -1
Multi: false

With script, you can't use %1, it has to be this[1]. Also changed the pattern, just in case.
Taruin
Soludra it looks like you're decrementing number but don't seem to check its value at any point, I'm assuming you want to test for number == 0 in your walk function before calling addTimer again?

To the OP, I'm not entirely sure what you want to do, but this would be a basic speedwalking alias:

Pattern:
CODE
^walk (\d+) (.*?)$

Send:
CODE
dirs = this[2].split(" ")
walk_timer = 0
function do_walk(){
  send(dirs[walk_timer])
  walk_timer++
}
addTimer(this[1], "do_walk()", dirs.length)

Make sure enabled, script and regexp are true.

Usage would be:
walk <delay> <directions>

Example:
walk 2 n ne s in down e w

You have to be careful of your variable scope with this code, but there are multiple ways to do something like this. In practice you would probably move the walk_timer variable and the function outside of the alias into some kind of initialization script that you triggered on login. You could also hardcode the delay value if known of course.
Kazuya
Hey thanks Taruin that worked out well. I actually would like to set the delay to be 1 second. What might I have to change in order to set that everytime I use it?

Also, my goal for once I get this set up is to create an alias that can walk to a place, do an action, walk to another place, do another simple action, repeat.
Taruin
Try and figure out for yourself how to adapt the code to always use a delay of one second. You only have to make two minor changes, one in the pattern and one in the send. If you can't get it to work post what you have tried and someone may be able to help you.

You could use the alias as it is to perform any single word command, not just movement.

Kazuya
So when using the "walk <delay> <directions>" alias, what might I need to do so that I can use it as one step of many in my master alias? I'm guessing something is wrong with the priority setting as when I try to execute it, I get an error as if I am trying to walk to a landmark instead of using my alias.

Edit: Turns out its probably not anything to do with priority as I just adjusted a couple things without any results. Also, I remembered that you cannot use an alias in another alias. Any ideas to get around this? If it is easier, I do know the directions I want to go ahead of time. In this master alias I am refering to I do not want there to be any variables if anybody understands that.
Soludra
QUOTE (Kazuya @ Jun 14 2009, 08:21 PM) *
Also, I remembered that you cannot use an alias in another alias. Any ideas to get around this?


Use execute(), and it'll pass through alias checking before being sent.
Kazuya
Unfortunately by doing that you must enable script which makes it so when I type my alias and hit enter, it will not send.
Soludra
QUOTE (Kazuya @ Jun 15 2009, 10:48 AM) *
Unfortunately by doing that you must enable script which makes it so when I type my alias and hit enter, it will not send.


Then you just convert your Send input to script-style. It's not really that hard; you can post here and someone might be willing to help, if it's that beyond you. smile.gif
Kazuya
Because my plan involves just simple actions, I put the walking alias as execute(walk <seconds> <directions>); and all of the other steps I would just have normally sent to the server as send('<text>');. My problem still lies that often when I enable things as script and go to use them, I am not able to hit enter to start the alias. Is there a Java Script command that simply puts a pause or delay in the code and then resumes? I'm checking out setTimeout(<code>, <milliseconds>); but am not able to get it working as of now either.
Kazuya
QUOTE (Taruin @ Jun 15 2009, 02:53 AM) *
To the OP, I'm not entirely sure what you want to do, but this would be a basic speedwalking alias:

Pattern:
CODE
^walk (\d+) (.*?)$

Send:
CODE
dirs = this[2].split(" ")
walk_timer = 0
function do_walk(){
  send(dirs[walk_timer])
  walk_timer++
}
addTimer(this[1], "do_walk()", dirs.length)

Make sure enabled, script and regexp are true.

Usage would be:
walk <delay> <directions>

Example:
walk 2 n ne s in down e w

You have to be careful of your variable scope with this code, but there are multiple ways to do something like this. In practice you would probably move the walk_timer variable and the function outside of the alias into some kind of initialization script that you triggered on login. You could also hardcode the delay value if known of course.


Unfortuantely, this no longer works for me either although it did at first. I fear I have become too confused with multiple ways of doing things. If a speedwalking alias would help, that would be great, but all I truely need is a syntax that will insert a delay of, say half a second, before executing the next line of code.
Taruin
If the alias is no longer working it's possible that the backslash character is missing from the pattern field. This is a known bug and hopefully should be fixed soon. If you add the \ back in it should work again. You could replace the (\d+) with ([0-9]+) and this would solve the problem too.

Unfortunately there is no such thing as a simple command to insert a pause or delay between actions in a script, instead you have to specify some code to evaluate after a specified time, such as with the addTimer function.

If you just want to put in time delays you could do something like this:
CODE
addTimer(1, "send('sit')")
addTimer(3, "send('stand')")
addTimer(7, "send('look')")
addTimer(12, "send('north')")

Note that the time intervals all count from the start, not from the previous action, so in this example your character would sit after 1 second, then stand after a further 2 seconds, then look 4 seconds later, then finally move north 5 seconds after that.
Kazuya
I just tested out the barebone addTimer code provided and it seems to work just like I need it to. Now I just need to change it slightly to make it work for my situation. I will also try to fix that speedwalking alias later today.
Kazuya
It seems as if using that syntax did work, and pretty nicely I might add. Unfortuantely my code is quite basic, however it does work. I will also add that the missing backslash was the fix for the speedwalking alias. I wish it could work with numbers such as 0.5 however I probably shouldn't be so picky. Thanks to the both of you that helped out with this project of mine. A 5 minute task that I did at nearly every login is now automated to a 2 minute alias!
Taruin
QUOTE
I wish it could work with numbers such as 0.5 however I probably shouldn't be so picky.

It should work with 0.5 just fine, infact the timers are measured internally in milliseconds so in theory you could have a delay of 0.499 seconds, although I'm not sure there would be much point!
Kazuya
It may work but I have been having problems getting the entire alias to work still. I check for the backslash now but many times it is getting confused for the WALK TO <landmark> command. Havent been able to figure out when it works and when it doesn't quite yet.
Soludra
QUOTE (Kazuya @ Jun 18 2009, 03:13 PM) *
It may work but I have been having problems getting the entire alias to work still. I check for the backslash now but many times it is getting confused for the WALK TO <landmark> command. Havent been able to figure out when it works and when it doesn't quite yet.


Can you Export your settings file (hit Export at the bottom of the aliases or triggers menus) and copy its contents to http://achaea.pastebin.com/? It would be a lot easier to diagnose this way, I think, because then we'd be able to see exactly what you're using.

EDIT: Post the URL in the address bar when you've pasted and sent, that way we can actually get to it.
Kazuya
QUOTE (Soludra @ Jun 18 2009, 11:47 PM) *
EDIT: Post the URL in the address bar when you've pasted and sent, that way we can actually get to it.


Hopefully this link will work http://achaea.pastebin.com/m3cfb3cc5. I have even tried disabling everything else (all other aliases and triggers and macros) to make sure nothing else was effecting this so you can know thats not a problem.
Taruin
This:
CODE
Pattern:  ^walk (/d+) (.*?)$


should be this:
CODE
Pattern:  ^walk (\d+) (.*?)$


Note that it's a back slash rather than a forward slash.

You could also replace it with the following pattern that will avoid the backslash bug:

CODE
Pattern:  ^walk ([0-9]+) (.*?)$
Kazuya
QUOTE (Taruin @ Jun 19 2009, 07:54 PM) *
Note that it's a back slash rather than a forward slash.

You could also replace it with the following pattern that will avoid the backslash bug:

CODE
Pattern:  ^walk ([0-9]+) (.*?)$


You know what now that you mention that I remember changing it once to a backslash and then it must have got thrown out again so I put in a forward slash not remembering. I'll just change it to the other way to avoid confusion in the future.

EDIT: I just switched the alias to the code I quoted and it works, so this would be the code I would recommend people use if they too are doing a speedwalking alias. Thanks again Taruin.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.