Help needed for basic scripting

Post Reply
sigur
Posts: 4
Joined: Sat Dec 25, 2010 9:57 pm

Help needed for basic scripting

Post by sigur »

So, I'm a complete newbie when it comes to pretty much any form of scripting including with Lua, so I apologize ahead of time for my ignorance. I used MUSHclient awhile back, though I used VBscript, and I could do the basics with that, although I'm not sure if I remember much of it. If any has an knowledge of both VB and Lua and could relate them some how, that would be cool.
Anyway, I started this topic because I read parts of the manual and the other resources posted in the announcement by Heiko, and it was sort of confusing. I just want to start off by making a variable tracker, and then a corresponding alias with 'if' statements, so my character will perform different actions depending on the value of the variable...



So:



"You quickly flow into the x stance" triggers the variable stance = x


Then the alias att performs a series of 'if' statements like:

If stance = x then
do a

If stance = y then
do b

....and so on.



If I remember right, I think with VBscript in MUSH I did something like this, if this helps anyone:

dim t
dim stance

t = world.getvariable ("t")
stance = world.getvariable ("stance")

if stance = Ein-Fasit then
world.send ("sitara vertical ") & t
world.send ("sitara lateral ") & t
world.send ("sitara vertical ") & t
end if

if stance = Vae-Sant then
world.send ("sitara lateral ") & t
world.send ("sitara vertical ") & t
world.send ("sitara lateral ") & t
end if



That's off the top of my head, but I think its right. Sorry again for my ignorance of scripting, and thanks a lot for your help.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Help needed for basic scripting

Post by Heiko »

add a trigger with this pattern (type Perl regex):
^You quickly flow into the (\w+) stance
then you put this script in the input box below the trigger pattern list:
Code: [show] | [select all] lua
myStance = matches[2]
The alias looks like this:
pattern:^att$
script:
Code: [show] | [select all] lua
if myStance == "x" then 
    send("kill monster bla") 
end
if myStance == "foo" then 
    send("shout help!") 
end

sigur
Posts: 4
Joined: Sat Dec 25, 2010 9:57 pm

Re: Help needed for basic scripting

Post by sigur »

Thanks! Two things... first, could you break down each component of the scripting and explain why you did what you did. And second, I need an alias that adjusts another variable called target, and then that variable needs to be incorporated into the alias you just helped me with so there are essentially TWO variables within the alias: stance and target.

sigur
Posts: 4
Joined: Sat Dec 25, 2010 9:57 pm

Re: Help needed for basic scripting

Post by sigur »

I've been messing around with it and I have this:

Targetting alias:

Pattern:
^t (\w+)

Script:
myTarget = matches[2]
echo("Target = " .. myTarget)


Stance trigger:

Pattern:
^You quickly flow into the (\w+) stance. [and I did perl regex]

Script:
myStance = matches[2]
echo("Stance = " .. myStance) [and I did that in the huge box at the bottom of the window]


Attacking alias:

Pattern:
^att

Script:
if myStance == "Ein-Fasit" then
send("sitara vertical " .. myTarget)
send("sitara lateral " .. myTarget)
send("sitara vertical " .. myTarget)
end

if myStance == "Vae-Sant" then
send("sitara lateral " .. myTarget)
send("sitara vertical " .. myTarget)
send("sitara lateral " .. myTarget)
end


The targetting alias works... at least the echoing part does. I'm not sure how to check if the variable is actually changing. But the stance trigger doesn't work and I'm sure that's why the attacking alias doesn't either. Anyway, if you could tell me what's wrong, that'd be great... and if you could still break down the scripting and tell me why you did what you did, that'd be even better. Thanks.

Parnakra
Posts: 35
Joined: Tue Apr 21, 2009 10:48 am

Re: Help needed for basic scripting

Post by Parnakra »

sigur wrote:

Code: Select all

^You quickly flow into the (\w+) stance.
In a regex, a period is interpreted as any one symbol. If you want the regex to match against an actual period, you have to escape it with a backslash (\), so your trigger pattern should be:

Code: Select all

^You quickly flow into the (\w+) stance\.
This is not the dealbreaking problem here, though (just a bit of advice for your future scripting sanity).

In a regex, \w is interpreted as a single character (anything in the range of a-z or A-Z). The added plus sign just means you only want to catch one or more of those characters. Now, from what I can make out from the rest of your code, the stance you're trying to use has a dash (-) in its name, so the pattern \w+ won't catch that name as a whole. Instead, you should use the period I talked about (matches any single symbol as opposed to only characters).

So, your pattern as it should be:

Code: Select all

^You quickly flow into the (\.+) stance\.
That should work.

sigur
Posts: 4
Joined: Sat Dec 25, 2010 9:57 pm

Re: Help needed for basic scripting

Post by sigur »

That did work. Thanks a lot.

Post Reply