Wildcards/function

Post Reply
Zenith
Posts: 11
Joined: Sat Jul 09, 2011 7:29 am

Wildcards/function

Post by Zenith »

/// This line appears on the mud and i want to capture the bolded parts.
/// Your base abilities are: Str:13 Int:14 Wil:18 Dex:15 Con:10.

/// So i use this as a perl regex expression.
Your base abilities are: Str:(\d+) Int:(\d+) Wil:(\d+) Dex:(\d+) Con:(\d+).

Str = matches[2]
Int = matches[3]
Wil = matches[4]
Dex = matches[5]
Con = matches[6]
echo (Str .. ' ' .. Int .. ' ' .. Wil .. ' ' .. Dex .. ' ' .. Con)

/// And i get this result on my screen: 13 14 18 15 10
/// So far so good.

/// Now i want to have this function check if three of the stats are above x number, so i write it this way:

function checkstats()
if Str >= 15 and Dex >= 17 and con >= 13
then
/// What command do i use to play of a sound file here?
return true
else
send ('restat')
return false
end
end

/// And i try to run it:
checkstats()

/// It doesn't work and i get this in the debugger:::
/// LUA: ERROR running script STATS (Trigger34) ERROR:[string "function Trigger34()..."]:10: attempt to
/// compare number with string

/// Teach me master, do i have to declare the variables as integer or something?? Am i using wrong type of wildcards?!

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: Wildcards/function

Post by kevutian »

Hi, Zenith. Dead easy to fix this. Simply replace all your lines, following this method:
Code: [show] | [select all] lua
Str = tonumber(matches[2])
Lastly, the function you need here is playSoundFile(). You can find more details on it from the wiki page: http://wiki.mudlet.org/w/Manual:Lua_Fun ... ySoundFile

Hope that helps.

Zenith
Posts: 11
Joined: Sat Jul 09, 2011 7:29 am

Re: Wildcards/function

Post by Zenith »

Thank you!

Zenith
Posts: 11
Joined: Sat Jul 09, 2011 7:29 am

Re: Wildcards/function

Post by Zenith »

// It now looks like this.

Str = tonumber(matches[2])
Int = tonumber(matches[3])
Wil = tonumber(matches[4])
Dex = tonumber(matches[5])
Con = tonumber(matches[6])
echo ("\n" .. Str .. ' ' .. Int .. ' ' .. Wil .. ' ' .. Dex .. ' ' .. Con)

function checkstats()
if Str >= 15 and Dex >= 17 and con >= 13
then
echo ("You got it!")
return true
else
send ('restat')
send ('k sapling')
return false
end
end
checkstats()

/// New Error: LUA: ERROR running script STATS (Trigger34) ERROR:[string "function Trigger34()..."]:10: attempt to compare number with nil

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Wildcards/function

Post by chris »

case error. Variables are case sensitive, Con != con.

Zenith
Posts: 11
Joined: Sat Jul 09, 2011 7:29 am

Re: Wildcards/function

Post by Zenith »

Aha thanks! I always miss those!

Post Reply