Page 1 of 1

MM creates & calls a macro dynamically?

Posted: Sat Apr 27, 2013 1:58 am
by wps
I found the in game macro efficiency is better than mm script.
I has trouble when some other player is competing the NPC chatting with me.

I guest he/she is using macro.

So I tried this macro, and it's faster than the same implement in MM.
I guest there is some communication overhead between MM and client.

Code: Select all

/run ChoiceOption(1);
/wait 0.2
/run ChoiceOption(1);
Is there any possibility that we could create a macro dynamically,
and call it in script?
After the script finished, delete the macro automatically.

Thanks.

Re: MM creates & calls a macro dynamically?

Posted: Sat Apr 27, 2013 4:34 am
by rock5
Normally you can do a bunch of commands in one script which is made easier with the new "RoMCode" function, thus avoiding the overhead of multiple commands but "wait" is a slash command so I don't know if it's possible to do except in a separate command. It might be possible to write a function that uses the macro writing functions and write the macro then press the macro key but it would require that the macro be in your action bar.

I just tested this, it worked.

Code: Select all

	local command = "/run ChoiceOption(6);\n/wait 2\n/run ChoiceOption(1);"
	writeToMacro(commandMacro, command, COMMAND_MACRO_NAME)
	keyboardPress(key.VK_0)
It assumes you have the macro in the 10th actionbar slot. Note: "\n" means "new line". You could easily make it into a function that accepts any set of commands as an argument.

Re: MM creates & calls a macro dynamically?

Posted: Sat Apr 27, 2013 4:49 am
by lisa
beat me to it, I was going to say you will need to use next line in order to use the /wait in the middle of a macro using MM, otherwise it just won't work. since the /wait in the example is only 0.2 you could probably do it without the wait. It all depends on ping and such.

Re: MM creates & calls a macro dynamically?

Posted: Mon Apr 29, 2013 9:10 am
by wps
Firstly, I checked the function.lua and macro.lua.
It looks like the macro should be able to run by SendMacro or ROMScript,
but it is not.

I finally got time to try Rock's solution today, and it works.

However, I don't understand why we have to drag the macro to action bar 0 first.
I tried

Code: Select all

keyboardPress(settings.profile.hotkeys.MACRO.key);
and

Code: Select all

keyboardHold(settings.profile.hotkeys.MACRO.key);
rest(100)
keyboardRelease(settings.profile.hotkeys.MACRO.key);
.
They don't work.

Is there anything I misunderstood?

Thanks for your helping.

Re: MM creates & calls a macro dynamically?

Posted: Mon Apr 29, 2013 10:23 am
by rock5
Basically, pressing the "commandmacro" key (F9) doesn't execute the macro directly, it reads the macro and executes the commands found there as a function or code. In the case of slash commands it assumes it's a one line slash command and uses the ExecuteMacroLine command to execute it. This fails if the macro has multiple slash commands. I just fixed it to execute the lines separately but it executed all lines instantly, the /wait 2 had no affect. I suspect that running a macro normally causes it to wait for each line to complete before continuing to the next line but executing them with the ExecuteMacroLine function doesn't wait or maybe "wait" just doesn't work with that function. So, at least for macros that include the "wait" command, you will still need to use the action bar key.

Re: MM creates & calls a macro dynamically?

Posted: Mon Apr 29, 2013 10:57 am
by wps
Thanks Rock.