PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Mardeg on 18 June, 2005, 11:41:36

Title: need to get tokenize function working
Post by: Mardeg on 18 June, 2005, 11:41:36
I didn't realize how much I was using this function until it stopped working when I transferred it from the old lua 4 script:
function tokenize(inString,token)
_WORDS = {}
local matcher = "([^"..token.."]+)"
string.gsub(inString, matcher, function (w) table.insert(_WORDS,w) end)
return _WORDS
end
 

If anyone recognizes it and can make it work in lua 5 that would make my day.
Title:
Post by: jiten on 18 June, 2005, 13:43:31
Maybe if you post the whole script we can sort it out.

Best regards
Title:
Post by: ??????Hawk?????? on 18 June, 2005, 14:11:11
QuoteOriginally posted by Mardeg
I didn't realize how much I was using this function until it stopped working when I transferred it from the old lua 4 script:
function tokenize(inString,token)
_WORDS = {}
local matcher = "([^"..token.."]+)"
string.gsub(inString, matcher, function (w) table.insert(_WORDS,w) end)
return _WORDS
end
 

If anyone recognizes it and can make it work in lua 5 that would make my day.

Hi m8  

your Problem is not with this function but most likely the way you Call it...

strQSep = "*"
tTable = tokenize(line,strQSep)

Calling it with the above, line should contain a string in this format:-

text[COLOR=red]*[/COLOR] text

or:-

anything you want here[COLOR=red]*[/COLOR] more info here


and then you can get your Split string with the following simple loop:-
for index, value in tTable do

using the Second line example
index = "anything you want here"
value = "more info here"

Hope this helps



??????Hawk??????
Title:
Post by: Mardeg on 18 June, 2005, 21:41:33
I was definitely misusing that function then. It forced me to use the string.find function I should have used from the start and ditch tokenize altogether.

On a separate note, I noticed ptokax doesn't SendToAll when the "".. is removed from the beginning of the lines sent in the following code, but it doesn't throw an error either. It looks like concatenation is being relied on for reasons beyond me. Should I report that as a bug?

if (cmd==prefix.."8") then
if string.sub(data,-1) == "?" then
answers = {}
for line in io.lines(answersfile) do table.insert(answers, line) end
SendToAll(Bot, ""..string.gsub(answers[math.random(table.getn(answers))], "%b[]", user.sName))
answers = nil
else
insults = {}
for line in io.lines(insultsfile) do table.insert(insults, line) end
SendToAll(Bot, ""..string.gsub(insults[math.random(table.getn(insults))], "%b[]", user.sName))
insults = nil
end
Title:
Post by: Dessamator on 18 June, 2005, 21:48:41
nop, theres no error there, u cant "concatenate" a something that doesnt exist , so in this case all u need to do is :

change this ::

SendToAll(Bot, ""..string.gsub(answers[math.random(table.getn(answers))], "%b[]", user.sName


to this :

SendToAll(Bot, string.gsub(answers[math.random(table.getn(answers))], "%b[]", user.sName
P.S. im not so sure u can use string.gsub inside sendtoall, maybe u should do that outside the api store it in a variable , and then send the data !

Title:
Post by: Mardeg on 19 June, 2005, 00:52:10
The script I posted is the working version, you have it the other way around, removing the "".. stops  it from working. I just commented that there is no corresponding error message when that happens.
Title:
Post by: Dessamator on 19 June, 2005, 11:20:38
hm, indeed the brackets seem to make all the difference. nicely done mutor :)