Page 1 of 1

how to create a function that runs another?

Posted: Thu Nov 06, 2014 10:44 am
by Lamkefyned
Hi, I am making a user function and I want to make a function that is running another inside.

Example:

Code: Select all

function LKCore()

	-- COUNT ROUND
		Rcount = 0
		local function countround()
			Rcount = Rcount+1;
		end

end

Code: Select all

LKCore("countround()")
if anyone knows and can help me ... Thank you

Re: how to create a function that runs another?

Posted: Thu Nov 06, 2014 10:57 am
by rock5
When you use "function" you are creating a function, not running it. What does is create a local function and then not use it.

I can't make a suggestion because I don't know what you are trying to do.

Re: how to create a function that runs another?

Posted: Thu Nov 06, 2014 5:37 pm
by Lamkefyned
I mean calling a function that is inside another ....

for a single function ....

Re: how to create a function that runs another?

Posted: Thu Nov 06, 2014 9:55 pm
by rock5
Do you mean you want to pass an argument to a function telling it which function to use?

Well the bot does something like this when using eval functions eg. :)

Code: Select all

player:findEnemy(true,nil evalTargetDefault)
player:findNearestNameOrId(""",nil,evalTargetLootable)
In this case it just passes the whole function as the argument.

Is it a requirement for you to use local functions inside the main function? In that case it would be a bit more tricky. You could use a local table to hold the local functions eg.

Code: Select all

function mainFunc(funcname)
   local funcs = {}
   function funcs.f1()
       -- do something
   end
   function funcs.f2()
      -- do something
   end
   funcs[funcname]()
end
Then you could call them with

Code: Select all

mainFunc("f1")
mainFunc("f2")

Re: how to create a function that runs another?

Posted: Fri Nov 07, 2014 9:31 am
by Lamkefyned
this is just what I want

but can pass parameters to the function inside ....?

Code: Select all

mainFunc("f1(3)")

mainFunc("f1("33")") -->>> this would mistake?

Re: how to create a function that runs another?

Posted: Fri Nov 07, 2014 9:54 am
by rock5
Maybe as extra arguments.

Code: Select all

function mainFunc(funcname, ...)
   local funcs = {}
   function funcs.f1(a)
       -- do something
   end
   function funcs.f2(a, b, c)
      -- do something
   end
   funcs[funcname](...)
end

Code: Select all

mainFunc("f1",1)
mainFunc("f2",1,2,3)

Re: how to create a function that runs another?

Posted: Sat Nov 08, 2014 10:18 am
by Lamkefyned
Thank R5