Problem with args
 

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

Problem with args

Started by nErBoS, 19 October, 2003, 02:10:33

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nErBoS

Hi all,

I am having troblems with the args for example

function GetArgML(data)
	s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
	return arg

function XXXX(user, data)
GetArgML(data)
local xpto = GetItemByName(arg)
 --and any function

This works fine, but some times the script editor gives me this error:

"Syntax Error: attempt to index local `xpto' (a nil value)"

And the functions stop working !

Am I doing somthing wrong ???

Best regrads, nErBoS
--## nErBoS Spot ##--

nErBoS

Is there anyone who can help me in this problem ???
--## nErBoS Spot ##--

Skrollster

#2
QuoteOriginally posted by nErBoS
Hi all,

I am having troblems with the args for example

function GetArgML(data)
	s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
	return arg

function XXXX(user, data)
GetArgML(data)
local xpto = GetItemByName(arg)
 --and any function

This works fine, but some times the script editor gives me this error:

"Syntax Error: attempt to index local `xpto' (a nil value)"

And the functions stop working !

Am I doing somthing wrong ???

Best regrads, nErBoS


test this
function GetArgML(data)
	s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
	return arg
end

function XXXX(user, data)
local arg = GetArgML(data)
local xpto = GetItemByName(arg)
 --and any function

nErBoS

No, got the same error  :(
--## nErBoS Spot ##--

Skrollster

are you sure the user is online??

GetItemByName(arg) only works on online users

pHaTTy

Check it with a if nil statement
Resistance is futile!

nErBoS

Quoteare you sure the user is online??

GetItemByName(arg) only works on online users

yes i know !!

QuoteCheck it with a if nil statement

didn?t understand !!
--## nErBoS Spot ##--

pHaTTy

function XXXX(user, data)
local arg = GetArgML(data)
if arg == nil then 
user:SendData("No such user") 
end
else
local xpto = GetItemByName(arg)
--whatever

-phatty
Resistance is futile!

Skrollster

function XXXX(user, data)
local arg = GetArgML(data)
if arg == nil then 
user:SendData("No argument")
else
local xpto = GetItemByName(arg)
if xpto then
-- your code
else
user:SendData("Couldn't find "..arg.." online")
end
--whatever

nErBoS

Still gives me the same error !!  :(
--## nErBoS Spot ##--

Skrollster

is it possible to see more of your code???

nErBoS

elseif (cmd=="!gag") then
			local arg = GetArgML(data)
			if arg == nil then 
			user:SendData(Bot, "N?o foi encontrado user !!") 
			else
			local gagged = GetItemByName(arg) 
			gagged:SendPM(Bot, "Foste impedido de falar no Main-Chat !")
			SendPmToOps(Bot, "O utilizador "..gagged.sName.." foi impedido de falar no Main-Chat por "..user.sName.." !")
			end
			return 0

This is one of the functions where e get the error
--## nErBoS Spot ##--

Skrollster

Try as i did in my example code..

nErBoS

I think the probel is this i typed

"!gag nerbos"

and aperas this..

[21:37] Couldn't find nerbo online
[21:37] *** nErBoS has gagged: nErBoS


there for the problem i think is with the function arg do you know a function for long args ??
--## nErBoS Spot ##--

Skrollster

long args??

!gag skrollster because he doesn't know a damn thing

s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(.+)")

will return
cmd = "!gag"
arg = "skrollster because he doesn't know a damn thing"

s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(%S+%s+%S+)")

will return
cmd = "!gag"
arg = "skrollster because"

Skrollster

i know why it doesn't work, lua is case sensitive

SkRoLlStEr isnt the same thing as Skrollster

nErBoS

#16
sorry a bad explaintion from my part !!

if you notice i wrote in the comand my nick and on the retrive the bot sends my nick without the "s"

i think this must be a problem with the arg function !!
--## nErBoS Spot ##--

Skrollster

i think i know what the problem is but i'm not sure..

i guess that you cut the end of data 2 times

do you do this twice??

   -- remove end pipe
   data=strsub(data,1,strlen(data)-1)

nErBoS

i think is this that you are meaning...

if (strsub(data, 1, 1) == "<") or (strsub(data,1,4) == "$To:")  then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
--## nErBoS Spot ##--

Skrollster

what i asked was if you did cut it of twice

nErBoS

sorry but my english is not very good !!

i am not understandig you question !!!!
--## nErBoS Spot ##--

Skrollster

is it possible for me to see your whole script??

it would help me a lot

nErBoS

Great !! I will send you the script in pm, becuase is big !!

Some of the functions you will reconize because i got from your bot : )
--## nErBoS Spot ##--

Skrollster

ok, hurry up, i have to get som sleep =)

nErBoS

--## nErBoS Spot ##--

SMF spam blocked by CleanTalk