Lua in CMUD

by Trakis

Back to Mechanic's Corner.

Trakis2008-05-13 13:19:59
Hey.

So I've been messing around with CMUD, and I've been using the following trigger to test something:

The pattern is: You say, "(.+)"

And the script, in Lua, does this:

print("You said something.")


That seems to work.

But what I'd like to do, is to print what is captured by (.+)

How do I do this? CMUD does not respond when I try to refer to it as %1, and I have tried (.+){stuff}, but then the pattern no longer matches. Has anyone managed to get this to work? Can't seem to find anything on the CMUD forums, either.
Unknown2008-05-13 13:47:53
CODE
print("You said "..zs.param(1))
Trakis2008-05-13 15:00:26
Awesome informative response as usual. Your posts have an effect of enlightening me, while at the same time, making me feel kind of dumb.
Trakis2008-05-15 05:45:46
A continuation:

I was testing using zs.param(1) to capture variables by writing a simple trigger that would capture all the variables from the prompt. This is my test trigger:

Pattern: ^(\\d+)h, (\\d+)m, (\\d+)e, (\\d+)p, (\\d+)en, (\\d+)w (\\w+)-$

Script:
CODE
p_health = zs.param(1)
p_mana = zs.param(2)
p_ego = zs.param(3)
p_power = zs.param(4)
p_endurance = zs.param(5)
p_willpower = zs.param(6)
prompt_codes = zs.param(7)

print(zs.param(7))


What happens is really weird. CMUD prints '0' over and over again, showing that obviously the pattern matches, but parameter 7 isn't being properly stored. I also tried printing zs.param(7) directly, just to see. Still no go.

EDIT: Even weirder, I quit CMUD, reopened it, and it was working perfectly. Makes very little sense to me.
Unknown2008-05-15 11:01:44
That seems a little odd, but I just tried your code in my CMUD, and it worked perfectly.
Trakis2008-05-15 13:27:59
That seems so strange. Is it possible I have some sort of option or preference checked that makes things act strangely?
Unknown2008-05-15 13:47:26
It's possible that your options differ from mine, but I'm just using the defaults in the untitled session. It's also quite possible that CMUD or some library it relies on was just having a "mental moment," as they say. The client isn't bug-free yet, though it's a far cry better from what it was last year.
Trakis2008-05-15 15:00:02
Are you using the newest version of CMUD?
Unknown2008-05-15 16:15:27
Always. I'm using 2.25 Pro right now.
Trakis2008-05-16 04:37:55
I managed to recreate the problem. I had written some bad code to do this:

CODE
teststring = "Hello"
print(teststring)


When it printed, it would print "nil". Immediately after, the trigger from before would start printing 0's instead of the captured text. I have to restart CMUD to get the problem to go away.