PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: blackwings on 13 March, 2005, 07:49:26

Title: matching strings problem
Post by: blackwings on 13 March, 2005, 07:49:26
I have a problem to make a match between a string found through search with another string in a table. Here is what I'm trying to do = function DataArrival(user,data)
local inMsg = "(%p[^%.]+%p%S+)"
if inMsg then
user:SendData(Bot,"STRING FOUND")
if inMsg == (tLines[inMsg]==1) then -- the script works until I try to match here
user:SendData(Bot,"THE STRINGS MATCH")
end
end
end
Title:
Post by: Optimus on 13 March, 2005, 11:54:40
Quoteif inMsg == (tLines[inMsg]==1) then -- the script works until I try to match here
^^ This looks abit wierd, you need todo it in a way like this.

if tLines[inMsg] == 1 then  

^^ that is how a match should work

- Optimus
Title:
Post by: blackwings on 30 March, 2005, 03:12:31
QuoteOriginally posted by Optimus
Quoteif inMsg == (tLines[inMsg]==1) then -- the script works until I try to match here
^^ This looks abit wierd, you need todo it in a way like this.

if tLines[inMsg] == 1 then  

^^ that is how a match should work

- Optimus
Oh, sorry, seems like I missed that somone had answer the thread :P I tested your suggestion, but it still wont work when matching the string:( I have also tried to use senddata to see what the scripts finds, but the script shows the magic chars, not the string it found, so I can't really check whats wrong for myself :( Can anyone say whats wrong??? (my guess is that it doesn't remeber the string it founds, so how do I make so it remebers?) = Bot = "test"

tLines = {
[".no-ip.com"]=1,
}

function DataArrival(user,data)
local inMsg = "%p[^%.]+%p%S+"
if inMsg then
user:SendData(Bot,"STRING FOUND")
if tLines[inMsg] == 1 then -- stops working here
user:SendData(Bot,"THE STRINGS MATCH")
end
end
end
Title:
Post by: bastya_elvtars on 30 March, 2005, 04:19:13
Where is string.find?  8o
Title:
Post by: blackwings on 30 March, 2005, 05:04:16
QuoteOriginally posted by bastya_elvtars
Where is string.find?  8o
you mean = if string.find(data, inMsg,1,1) thenit doesn't work  :(
Title:
Post by: bastya_elvtars on 30 March, 2005, 05:38:41
if string.find(data, inMsg) you mean?
Title:
Post by: blackwings on 30 March, 2005, 06:59:57
QuoteOriginally posted by bastya_elvtars
if string.find(data, inMsg) you mean?
does the same thing as this = if inMsg thensomething is missing I guess :(  ?(
Title:
Post by: Jaras on 30 March, 2005, 11:25:22
it looks so simple, that probably i've missed something very, very important:

QuoteNot quite originally posted by blackwings
Bot = "test"

tLines = {
[".no-ip.com"]=1,
}

function DataArrival(user,data)
local inMsg = "%p[^%.]+%p%S+"
if inMsg then -- this is always a good condition, coz u're making this string not nil one line above...
user:SendData(Bot,"STRING FOUND")
if tLines[inMsg] == 1 then -- u mean if tLines["%p[^%.]+%p%S+"] == 1?
user:SendData(Bot,"THE STRINGS MATCH")
end
end
end

try this, but i'm not sure if it works:
sBot = "test"

tLines = {
[ ".no-ip.com" ] = 1,
}

function DataArrival( curUser, data )
local sData = string.lower( string.sub( data, 1, -2 ) )
local sPattern = "(%p[^%.]+%p%S+)"
local _,_,sBadString = string.find( sData, sPattern )
if sBadString then
curUser:SendData( sBot, "STRING FOUND" )
if tLines[ sBadString ] == 1 then
curUser:SendData( sBot, "THE STRING MATCH" )
end
end
end

p.s. but seriously - this isn't some kind of joke? if it's not hit me hard with mistakes i've made - whole code looks so innocent =]
Title:
Post by: blackwings on 30 March, 2005, 21:40:41
QuoteOriginally posted by Jaras
p.s. but seriously - this isn't some kind of joke? if it's not hit me hard with mistakes i've made - whole code looks so innocent =]
well, this code is for testing for a thing I can't seem to get to work. I have tried various ways, including what you did(but I tried your code, in case if I made a mistake before), but none of my tries have worked :(

I have read about similar things in the lua 5 mannual, but still no succes :(