Accessing a running macro with keywords or parameters

A forum for feature requests/discussions and user submitted patches that improve MQ2

Moderator: MacroQuest Developers

jrwalz
decaying skeleton
decaying skeleton
Posts: 4
Joined: Sat Nov 04, 2017 10:47 pm

Accessing a running macro with keywords or parameters

Post by jrwalz » Sat May 11, 2019 2:31 pm

I'm doing my own Healer macro, basically, I have it kind of finished, but it is not done with the adeptness that I desire. I want to be able to access instance variables or method parameters while a macro is running. I guess in a way that is similar to plugins. I have seen *.INI files set up with keywords with [ ] around them. So if for a very ruff example:

|** Sample *.INI **|

[Keyword]
name=off

|**********************|

and I type:
/keyword name=on |** To make the change **|

|**************** Sample Macro Method *******************|
/declare name String local NULL

Sub Name(String newName)
/echo ${newName}
/return

I would be able to indirectly access parameters in methods. I know that this might not make much sense, but that is really where I'm at. I know nothing about this, but I want to do my macro right and not have to repeat my work again. Would I use a /call statement to get the information from the *.IN file, how does the information get changed in the *.INI? If you could set me in a forward direction, I might be able to elaborate on this.

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: Accessing a running macro with keywords or parameters

Post by dewey2461 » Sat May 11, 2019 6:02 pm

Hi jrwalz, What you want to look at is:

https://www.macroquest2.com/wiki/index.php/TLO:Ini
https://www.macroquest2.com/wiki/index.php/Ini
https://www.macroquest2.com/wiki/index.php/Event
https://www.macroquest2.com/wiki/index.php/Bind


Lets start with reading in the variable from the ini file.

Code: Select all

|TLO -> string Ini[filename,section,key,default]
/varset Name ${Ini[myfile.ini,keyword,name,bob]}
This will read in the variable from file "myfile.ini", looking at the section [keyword], for they "key" name, and it will default to bob if it can not be found


Now lets say we want to save the variable out to the file for later

Code: Select all

|Slash command -> /ini "filename" "section" "key" "value"
/ini myfile.ini keyword name "${Name}"
This would write out to the file "myfile.ini" a section that would look like this:

Code: Select all

[keyword]
name=bob
Next you want to be able to turn this command on / off from the game. You can do that by events or using /bind or both. I can never get bind to work well so I'll let someone else explain it.

The old way of doing this is to come up with a system of "commands" you plan to pass into your macro and make an #event that would capture the command and let you process it.

For example: when I "/echo SET NAME VALUE" might be the syntax I want to use in game to change a variable.

Code: Select all

#event SET "[MQ2] SET #1# #2#"

Sub Event_Set(string line,string v1,string v2)
    /echo -- EVENT SET : line ${line} , v1 ${v1} , v2 ${v2}
    /if (${v1.Equal[NAME]}) {
         /varset name ${v2}
         /ini myfile.ini keyword name "${v2}"
    }
/return
The code above has not be checked for syntax but should gave you a rough introduction. Good luck !

jrwalz
decaying skeleton
decaying skeleton
Posts: 4
Joined: Sat Nov 04, 2017 10:47 pm

Re: Accessing a running macro with keywords or parameters

Post by jrwalz » Sat May 11, 2019 7:04 pm

Thank you so much Dewey. I was just reading someone else's code and saw the ReadIni and /varset Ini. There isn't very much info about this. What you give me here should be plenty enough for me to get to it.