Quick trigger problem in TF

by Simimi

Back to Mechanic's Corner.

Simimi2008-07-09 07:52:48
Here is what I am trying to do. I am back to that whole "trying to learn to really use tf" stage again, but this time I actually understand the basics of the help files, which makes me feel just peachy. As a test I am trying to trigger on a line to send something redundant back tot he mud, you know, just to see if I understand how to trigger things. The most confusing them for me about tf, coming from mush is that: In Mush when I have a trigger and I want it to "do" something, that something usually goes in the box beneath the trigger line... but for tf I assume it goes after the = \\ after the trigger? IE:
CODE
TF SCRIPT:

/def -mregexp -t '^You have played for a total of (\\d+) days, (\\d+) hours and (\\d+) minutes\\.$'  test = \\
  /send Works!


Now the original question here was how to get those (\\d+) expressions out as variables so I could do something with them. But the file itself doesn't seem to load, I get told that this is an illegal macro name, ie:
CODE
lines 5-6: def: illegal macro name " '^You have played for a total of (\\d+) days, (\\d+) hours and (\\d+) minutes\\.$'  test".


I am confused. This follows convention of other examples of working tf code that I have seen, and code that I am looking at presently.

Also, does -anyone- know how to make pageup/pagedown scroll through history and uparrow/downarrow go through my command history, Ala Mush? I know I need to write a keybinding but what does said bind do?

EDIT: Ok it turns out that apparently, on a trigger line (-t) your args and the beginning of the trigger need to be together, IE: (/def -mregexp -t'^You) etc etc. Now it loads, but it apparently is not matching properly as it does not send "Works!" to the screen. Does TF have a way to see how many times a trigger has been matched?
Unknown2008-07-09 11:32:54
Not 100% sure but try this maybe:


CODE
/def -mregexp -t'^You have played for a total of (+) days, (+) hours and (+) minutes\\.$'  test = /send Works: Days is %{P1} - Hours is %{P2} and minutes is %{P3}


I also -think- you may have gotten the illegial macro name error because you had a space between the -t and the first quotation sign. So it thought the trigger pattern was already the name or some such..

EDIT: I need to read edits.. If it doesn't send "works" I'd guess it doesn't match. I couldn't get the \\d+ patterns to work in TF. I'm not sure if it's TF or python (since I'm loading triggers through the python plugin and that screws with the patterns). Try using (+) for numbers and (+) for words.
Vathael2008-07-09 14:28:02
Now, I don't know... well, anything about TF but in a regex statement don't you need to put a \\ behind all the punctuation? Such as the "," that doesn't have one.
Simimi2008-07-09 14:29:24
Many thanks! I'll check it out... Is this some other form of regular expression? Thanks for the help and I'll look into it. I'll post here when I undoubtedly have more questions.

EDIT: as far as I know, not commas. As the other scripts I am using for reference do not \\ out their commas.
Vathael2008-07-09 14:31:45
Not really, no I just don't know if TF handles it different or anything. For example a regex prompt statement would look like..:

^(\\d+)h\\, (\\d+)m\\, (\\d+)e\\, (\\d+)p(?:\\, \\d+en)?(?:\\, \\d+w)? (.*?)(?:\\<\\>)?\\-

Another example I use:

^((@target).*) sprinkles a circle of salt around (him|her)self\\, and a shimmering
Eamon2008-07-09 16:14:35
Hi Simimi,

Looks like you figured out that tf's *really* picky about where you stick spaces. Watch for them at the end of lines, too, because it doesn't always like that.

As for your /send Works! command, that's actually the command to send text to the mud, so you won't necessarily see it (i.e. your trigger may be matching and you just don't realize it). You can do one of two things:

1) at the start of your tfrc file, do:
CODE
/set secho=on
/set sprefix=SENT>>>


This will echo anything that's sent to the mud, and prefix it with "SENT>>>". I find this really useful for debugging!

2) instead of /send, use /echo, eg.:
CODE
/echo Works!


That should give your little message.

Now, to use your (\\d+)'s as variables. Every piece of the regexp you put in ()'s goes into numbered variables called %P1 %P2, etc... (If you have the tf help files, it's explained in the user guide under "subs"). You can also get chunks of the regexp that happen to the left and right of the text you are matching using %PL and %PR, respectively, but that only works if you don't anchor the regexp.

As for the command history, I can step through my previous commands using up and down arrows without any kind of keybinding. I'm not familiar with the pageup/pagedown scrolling bit, so maybe I'm misunderstanding this part of your question.

Hope this is helpful! smile.gif Glad I'm not the only TF user here!

Oh, and comma's don't require the \\
At least I've never had an instance where not putting them has caused it to fail.
Simimi2008-07-09 19:35:30
Well I got it working but I am struggling with doing some basic math on the numbers. How do I echo the result of say (%P1 / 4) *6 ?
Eamon2008-07-09 20:50:09
I use something like this:

CODE
/test echo("the result is: $")


The $ defines a new scope and anything inside that is executed before it is returned to the echo.

EDIT: because I'm a noob and don't know how to make code tags... rolleyes.gif
Simimi2008-07-09 21:12:30
And why do I keep seeing things preceded with /test? I read the help file but its actual use vs non use is ambiguous at best, to me.

EDIT: and why do you use {P1} instead of %P1? I think I read you can not to arithmetic on %P1 but can on {P1}? If so, how do I know when to use which?
Eamon2008-07-09 21:25:44
Hehe, you know, I'm not entirely sure why myself. As I understand it, /test gives you the side effect of whatever function it calls without actually returning a value to the macro. So if you /test echo(), then you see the text in the mud just fine (the side-effect), but it doesn't return whatever value echo would normally return if called on its own. /test also lets you call things as functions (echo('text') as opposed to /echo 'text'), which I just find more intuitive.

I use /test echo for all my echoes, because I know it always works. Sometimes /echo on its own gives me weird errors, but when I throw /test in front of it, it's fine and doesn't complain. And if it ain't broke...
Eamon2008-07-09 21:37:26
Just saw your edit wink.gif

The % is an escape character that sort of tells tf to look up one scope. Usually, you only need one, and that takes you out to the "global" scope, so you can see all your variables. The problem comes when you start nesting expressions (remember, each new expression defines its own scope). Then you'd need to keep track of the right number of %'s to get you into the proper scope, which gets reeeeeeally messy after a while.

The {P1} syntax is better to use inside expressions, and in fact, I think the {}'s are required to call variables inside that $ construction. Most other cases, things like simple /set or /echo, you can easily get away with the %P1.

The scope thing takes a little getting used to, and I hope I'm explaining it properly. I'm not exactly a tinyfugue expert, but I remember going through pretty much exactly the sequence of questions that you are now when I was setting up my prompt triggers a few months ago when I started. I'm happy to keep answering your questions, at least until we run into the wall that is the extent of my knowledge. smile.gif
Simimi2008-07-09 21:46:10
Glad you are happy to answer because wow do I have lots of them! I sent you a pm, by the by, about scripting.