Some help, plesae ( gsub(), strfind() )
 

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

Some help, plesae ( gsub(), strfind() )

Started by Xico, 15 August, 2004, 15:27:52

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Xico

Hello ppl

Well I'm trying to develop some kind of client check and I'm stuck (my skils with Lua are still very poor)

sVersion = "0.3.3cvs20040611"
sTempVer = ""
gsub(sVersion, "([0-9.])", function(x) sTempVer = sTempVer ..x end)
After this sTempVer = 0.3.3

The question is: how can I get sTemVer = 0.33 ?

(And thanks to NightLitch, from who I got some good ideas, and some pieces of code)

NightLitch

QuoteOriginally posted by Xico
Hello ppl

Well I'm trying to develop some kind of client check and I'm stuck (my skils with Lua are still very poor)

sVersion = "0.3.3cvs20040611"
sTempVer = ""
gsub(sVersion, "([0-9.])", function(x) sTempVer = sTempVer ..x end)
After this sTempVer = 0.3.3

The question is: how can I get sTemVer = 0.33 ?

(And thanks to NightLitch, from who I got some good ideas, and some pieces of code)

try:

gsub(sVersion, "(%d+%.([%d+%.]))", function(x) sTempVer = sTempVer ..x end)

Not sure at all, but I think it should something like that.

/NL
//NL

Xico

#2
Well NightLitch you r my hero (don't take it wrong  :)  )but this time it doesn't work

From a sVersion= "0.3.3" I got a sTempVer = "0.3"
It laks the last digit

But tanks for the efort
(and sorry, but english is not my mother longuage)

Edited

and from sVersion= "0.3.020040508" I got sTempVer = "0.30.2".  

NightLitch

Try this one then:

function Main()
	sVersion = "0.3.3cvs20040611"
	sTempVer = ""
	sTempC = 0
	msg = gsub(sVersion, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
	SendToAll(msg)
end

Outcome:

0.33cvs20040611

dunno if this is how u want it...

Cheers / NL
//NL

NightLitch

Added a strfind to fix it like this:

sVersion = "0.3.3cvs20040611"
	sTempVer = ""
	sTempC = 0
	_,_,sVersion = strfind(sVersion, "([%.%d]+)")
	msg = gsub(sVersion, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
	SendToAll(msg)

Outcome:
0.33

NL
//NL

Xico

#5
Thanks NightLitch

I'm beeing a lot daring and i'm posting your VersionCheck() with "your" mod (I'm using it on my hub, a litle 1 with 110/150 users)
function VersionCheck(curUser, sCliente, vTag)

	local sDownload 	= tFazerDown[sCliente]
	local nVersao
	local nVersaoMin
	local sTempVer
	local msg

  	sTempC = 0
  	_,_,sTempVer = strfind(vTag["V"], "([%.%d]+)")
  	msg = gsub(sTempVer, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
  	nVersao = tonumber(msg)
  	sTempC = 0
  	_,_,sTempVer = strfind(tVersaoCliente[sCliente], "([%.%d]+)")
  	msg = gsub(sTempVer, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
  	nVersaoMin = tonumber(msg)
  	
	-- // debug Information
	--local usr = GetItemByName("Xico")
	--if usr then
		--usr:SendPM("Debug", "Cliente: "..sCliente.."   Tag: "..vTag["V"].."   MinVersion: "..nVersaoMin.."   ActVersion: "..nVersao)	
	--end
	
	if nVersao < nVersaoMin then
		Counter["MinVer"] = Counter["MinVer"] + 1
		curUser:SD(BotName,Arg(CC5, sCliente, "CLIENT", vTag["V"], "VERSION")) 
		curUser:SD(BotName,Arg(CC6, sCliente, "CLIENT", sVersao, "VERSION", sCliente, "CLI", sDownload, "DL"))
		curUser:Disconnect()
	end
end

Once more, many thanks for your help

NightLitch

//NL

SMF spam blocked by CleanTalk