need to get tokenize function working
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

need to get tokenize function working

Started by Mardeg, 18 June, 2005, 11:41:36

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

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.

jiten

Maybe if you post the whole script we can sort it out.

Best regards

??????Hawk??????

#2
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??????

Mardeg

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

Dessamator

#4
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 !

Ignorance is Bliss.

Mardeg

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.

Dessamator

hm, indeed the brackets seem to make all the difference. nicely done mutor :)
Ignorance is Bliss.

SMF spam blocked by CleanTalk