Basic way to call a function command
 

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

Basic way to call a function command

Started by ((UKSN))shad_dow, 11 January, 2004, 11:06:54

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

((UKSN))shad_dow

Dear All


can any body tell me please a basic way to all a function
command in the scripts .

example

function HelloNewUser(User)
                 
SendToAll(Bot,"Welcome  "..user.sName.." To Our Hub :)")

   
end

right thats a example fuction (syntex i think is ok.. LOL)

how do i call that fuction from the main part of the script

basicly all i wont it to undestand the basic command to call any fuction from in side  the  main body [function DataArrival(User)]

any help would be most helpfull :)

yours Shad  :D



creator of Therapy-X? bot

kepp

Just an example..
function WelcomeVIP(user)
end

function NewUserConnected(user)
  if user.iProfile == 2 then
     WelcomeVIP(user)
  elseif user.iProfile == 3 then
      WelcomeReg()
   end
end
Guarding    

((UKSN))shad_dow

cheers m8ty , undestand it now its in englisah .. lol  :D
creator of Therapy-X? bot

WooshMan

Hi, I have a question which I have asked NightLitch and think I have done his head in.

Please can someone help to save me killing his head all together.

OK.. I want all my commands in a seperate lua file and called from the main lua.

Here is my functionDA

function DataArrival(user, data)

   if( strsub(data, 1, 1) == "<" ) then
   return MainCommands(user, data)
   end
end


Here is my function MainCommands

function MainCommands(user, data)

   data=strsub(data,1,strlen(data)-1)
   local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
   if not cmd then cmd = "0" end
   cmd = strlower(cmd)

   local SendCommand = (GetCommands(user,data,cmd))

   if not SendCommand then
   return 1
   else
   return SendCommand -- here again returning the commands
   end

end

And here is my GetCommands

function GetCommands(user,data,cmd)

if user.iProfile == 0 or user.iProfile == 1 then
   if cmd == "mc" then
   mc(user,data,cmd,msg)
   return 1
   end   
end

function mc(user,data,cmd,msg)
   s,e,cmd,msg=strfind(data, "%b<>%s+(%S+)%s+(.*)")   
   whofrom = user.sName
   SendPmToAll(botname, msg .." ")
   return 1

      end

end


I have tried to follow existing scripts and have tried with NL's help, but I still can't get it.

Now I think it is my function something(user,data,x,x,x)
I am not sure what to put in.

the !mc command I am trying will send a mass PM to all users.

I get no script errors but I don't get PM's sent either.

Please help and explain in PLAIN English where I am going wrong... or even correct my code and maybe comment it so i can understand from there.

Thanks in advance and thanks for a great forum.

WooshMan
WooshMan

Creator of
originaltimebot.lua
www hubstats

Thanks to Plop, Kepp and NightLitch

WooshMan

Hi again....

I have spoken to Plop and he has explained where I was going wrong.

Here are my new files

function DataArrival(user, data)

   if( strsub(data, 1, 1) == "<" ) then
   MainCommands(user, data)
   end
end


function MainCommands(user, data)

   data=strsub(data,1,strlen(data)-1)
   local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
   if not cmd then cmd = "0" end
   cmd = strlower(cmd)

   GetCommands(user,data,cmd)
end

I had made the above to complicated for me to understand...lol



function GetCommands(user,data,cmd)

   if user.iProfile == 0 or user.iProfile == 1 then
      if cmd == "!mc" then
         mc(user,data,cmd,msg)
         return 1
      end
   end
end


function mc(user,data,cmd,msg)
   s,e,cmd,msg=strfind(data, "%b<>%s+(%S+)%s+(.*)")
   whofrom = user.sName
   SendPmToAll(botname, msg .." ")
   return 1
end

The line which reads if com =="!mc" then

is now correct... i had cmd=="mc" so it never saw the it.

Thanks Plop.

Thank you to NL for his help in getting me as far as he did.

WooshMan
WooshMan

Creator of
originaltimebot.lua
www hubstats

Thanks to Plop, Kepp and NightLitch

plop

http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

HaArD

Rally n00b question but what if I want to have a routine that requires no parms and returns no value?

Similar to calling a Sub in vbscript, how do I do that?
Define the Function as:
function DoStuff()
..
..
..
end function

and then call it with:
DoStuff()

NightLitch

ThX Woosh!

HaArD:

You will need to go by this ex:
function some(user,data)
if something then
DoStuff()
else
--dosimething else or nothing
end
end

hope this clear some for you
//NL

VidFamne

Are you thinking of this function, without any params or values?
function DoStuff()
--// i.e. SendToAll("Hi")
end

--// for example in Main

function Main()
DoStuff()
end

kepp

^^ like nigth said, you just call it by the name, Not as in bv were you call a command with 'Call'
Guarding    

NightLitch

QuoteBy VidFamne
Are you thinking of this function, without any params or values?

Of course it must be a value or param this was just a
basic explaination from me.

But he asked only how to call the function not the hole cake... :-)
//NL

VidFamne

#11
function DoStuff()
--// i.e. SendToAll("Hi")
end
function DoStuff(),
Surely dont need any parameters and it returns no value.
Just as HaArD asked for.

HaArD

I'd searched and searched and could not find a single script that did this so I was just a little unsure.

Thanks for all the replies and it works exactly as suspected and everyone replied. :D

SMF spam blocked by CleanTalk