seperating scripts into different files.

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

seperating scripts into different files.

#1 Post by zer0 » Wed Feb 20, 2008 8:25 pm

I've written up a shaiya bot, and I've found that the core of it shouldn't rarely needs changing, but the part that has user configurables, and the class custom functions do change.
Is their any way to seperate the code into different files? I'd like to have the main bot script in one file, the class specific functions in another, and finally the character configurables in another. Could this be done, or would it require a hard-code change, to MicroMacro?

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: seperating scripts into different files.

#2 Post by 3cmSailorfuku » Thu Feb 21, 2008 9:38 am

zerosignal wrote:I've written up a shaiya bot, and I've found that the core of it shouldn't rarely needs changing, but the part that has user configurables, and the class custom functions do change.
Is their any way to seperate the code into different files? I'd like to have the main bot script in one file, the class specific functions in another, and finally the character configurables in another. Could this be done, or would it require a hard-code change, to MicroMacro?
You could include a second LUA eg. config.lua etc, or read it from a text file. Though im not sure how wide micromacro supports LUA, but it expect everything to work. But having the config in the header of the file isn't that bad, or is it?

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: seperating scripts into different files.

#3 Post by Administrator » Thu Feb 21, 2008 1:23 pm

Correct. This is a standard feature of Lua. It has not been removed or limited from use in MicroMacro. The function is dofile(filename). If no argument is given, then it will read from standard input (typically, you do not want this -- that means it reads whatever you type in as a command). You should make note that the filename is based on MicroMacro's location; not the location of the script it is called from (basically, just remember to prelude the filename with "scripts/").

Example:

Code: Select all

  dofile("scripts/config.lua");

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: seperating scripts into different files.

#4 Post by zer0 » Thu Feb 21, 2008 6:45 pm

Thanks heaps, the script file was getting kinda large, and heavy to maintain. *Bounces off, to fix up his script*

spaghett1
Posts: 3
Joined: Sat Feb 23, 2008 6:21 pm

Re: seperating scripts into different files.

#5 Post by spaghett1 » Mon Feb 25, 2008 11:09 am

Nice topic :D ! So if you can separate config file like i always do using AutoIt, Can that config file be edited under micromacro using a GUI controls to edit or its not yet supported? Actually im starting to shift from using AutoIt to MicroMacro :mrgreen:

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: seperating scripts into different files.

#6 Post by Administrator » Mon Feb 25, 2008 12:12 pm

What do you mean? There is no GUI for MicroMacro, no. Not yet, anyways. You can use LuaEdit as a nice development environment for your lua scripts, though.

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: seperating scripts into different files.

#7 Post by 3cmSailorfuku » Mon Feb 25, 2008 4:44 pm

spaghett1 wrote:Nice topic :D ! So if you can separate config file like i always do using AutoIt, Can that config file be edited under micromacro using a GUI controls to edit or its not yet supported? Actually im starting to shift from using AutoIt to MicroMacro :mrgreen:
Make a gui for your config via VB, C++/C or even AutoIt. And why shifting from AutoIt to MicroMacro?

spaghett1
Posts: 3
Joined: Sat Feb 23, 2008 6:21 pm

Re: seperating scripts into different files.

#8 Post by spaghett1 » Tue Feb 26, 2008 6:21 am

Comparing AutoIt and micromacro on reading memory value especially for Health or HP, micromacro and Autoit responded very fast on the first read when HP goes lower than the set point, but on the second read Autoit responded veeery slow and character sometimes almost out of HP before it responded because of a very long long process or script shes reads to get memory new value , unlike micromacro it responded in a blink. Actually right now i use AutoIt for setting/editing config file and i plan use autoit too to launch micromacro and set what Lua file to load. :mrgreen:

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: seperating scripts into different files.

#9 Post by Administrator » Tue Feb 26, 2008 7:37 am

Ooh, yes, I see what you mean by GUI now. Just something for changing the config variables, right? Yeah, should be pretty simple to make something like that which would dump out a lua config script. Just have it do something like this:

Code: Select all

// untested, probably won't run out of the box.
void save_config(std::string filename, int dumpvars, char **varnames, char **varvalues)
{
  std::string output = "";
  printf("-- Auto-generated config file.\n\
          "-- Do not edit by hand.\n");
  for(int i = 0; i < dumpvars; i++)
  {
    printf("%s = %s;\n", varnames[i], varvalues[i]);
  }

  std::ofstream:: outfile;
  outfile.open(filename);
  if( outfile.is_open() )
  {
    outfile << output;
    outfile.close();
  }
}
However, this gives me an idea. I think it might be possible to create GUIs out of MicroMacro scripts with a bit of work, and adding in an additional (lite) library.

And as a final note, most people don't realize this but you can call MicroMacro with it's first (and only -- at the time being) argument being the filename of the script, and it will automatically open that script for you. So if you are trying to open it from AutoIT, you can use something like Execute("./micromacro/micromacro.exe ./scripts/myscript.lua"); The paths in my example might be a little bit off... It's best to use the full path for the lua script to run. This also means that if you right click on one of the lua scripts, and go to Open With, you can open it with MicroMacro and it'll run.

spaghett1
Posts: 3
Joined: Sat Feb 23, 2008 6:21 pm

Re: seperating scripts into different files.

#10 Post by spaghett1 » Tue Feb 26, 2008 8:37 pm

Also under Script folder i make another folder and named it Fiesta and placed all lua files only for Fiesta, to call or load fiesta.lua under micromacro is used "Fiesta/Fiesta.lua" :D . Do this to organize all lua files under script folder when u began on separating scripts into different files. ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests