Problem with DoAfterSpecial

Posted by Zorra on Sat 03 Oct 2009 11:37 AM — 5 posts, 21,304 views.

#0
I have a trigger does the following script when match found:

DoAfterSpecial (1, 'Simulate("Find enemies\n")', sendto.script)

However, the program prompts me an error box saying that

[string "Trigger: "]:18: unfinished string near ''Simulate("Find enemies'

What is the problem? When I execute

/world.Simulate("Find enemies\n")

it works just fine. Anyone can help? Thanks a lot in advance
Netherlands #1
Try:

DoAfterSpecial (1, 'Simulate("Find enemies\\n")', sendto.script)


The \n is interpreted by the 'outer' string and replaced by a newline. Causing the executed script to look like:

Simulate("Find enemies
")


And that is invalid syntax, since a string can't contain a literal newline. Adding the double backslashes makes the outer string turn it into a single backslash, which means the inner string still has a \n to convert.

Edit: Really late edit. Seems the forum somehow ate half the backslashes.
Amended on Sat 03 Oct 2009 12:32 PM by Worstje
Australia Forum Administrator #2
Worstje is right, in the "send" box, characters like \n are initially treated by MUSHclient as newlines, so to put them in a script you have to double the backslashes.

However I need to ask why you are using Simulate in a trigger? The Simulate was really intended for debugging scripts, by pumping through simulated MUD output.

What you have shown would put "Find enemies" on a line on its own, but you can use Note or ColourNote for that.

Simulate injects a simulated packet into the input stream, it may cause unexpected results if that packet happens to arrive between two packets from the MUD, perhaps breaking up MUD output in strange ways.
#3
Thanks a lot Worstje, it works now :D

To Nick, I am using the trigger to do send some control messages. The reason I am using simulate is that sometimes I have to do it offline, and that is the only way I found..
Netherlands #4
Zorra, the best way to do that would probably be to have a general control function of sorts (e.g. ControlFunction("Stop eating.") or something), and have your triggers and DoAfterFunc() call that.

Although I'd personally go straight to the source and set whatever variables would need setting, rather than simulating anything.