how to create a function that runs another?

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

how to create a function that runs another?

#1 Post by Lamkefyned » Thu Nov 06, 2014 10:44 am

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
If you think something is right just because everyone else believes,you're not thinking.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: how to create a function that runs another?

#2 Post by rock5 » Thu Nov 06, 2014 10:57 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: how to create a function that runs another?

#3 Post by Lamkefyned » Thu Nov 06, 2014 5:37 pm

I mean calling a function that is inside another ....

for a single function ....
If you think something is right just because everyone else believes,you're not thinking.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: how to create a function that runs another?

#4 Post by rock5 » Thu Nov 06, 2014 9:55 pm

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")
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: how to create a function that runs another?

#5 Post by Lamkefyned » Fri Nov 07, 2014 9:31 am

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?
If you think something is right just because everyone else believes,you're not thinking.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: how to create a function that runs another?

#6 Post by rock5 » Fri Nov 07, 2014 9:54 am

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)
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Lamkefyned
Posts: 348
Joined: Thu May 23, 2013 11:38 am
Location: Spain

Re: how to create a function that runs another?

#7 Post by Lamkefyned » Sat Nov 08, 2014 10:18 am

Thank R5
If you think something is right just because everyone else believes,you're not thinking.

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 9 guests