Page 1 of 1

seperating scripts into different files.

Posted: Wed Feb 20, 2008 8:25 pm
by zer0
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?

Re: seperating scripts into different files.

Posted: Thu Feb 21, 2008 9:38 am
by 3cmSailorfuku
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?

Re: seperating scripts into different files.

Posted: Thu Feb 21, 2008 1:23 pm
by Administrator
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");

Re: seperating scripts into different files.

Posted: Thu Feb 21, 2008 6:45 pm
by zer0
Thanks heaps, the script file was getting kinda large, and heavy to maintain. *Bounces off, to fix up his script*

Re: seperating scripts into different files.

Posted: Mon Feb 25, 2008 11:09 am
by spaghett1
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:

Re: seperating scripts into different files.

Posted: Mon Feb 25, 2008 12:12 pm
by Administrator
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.

Re: seperating scripts into different files.

Posted: Mon Feb 25, 2008 4:44 pm
by 3cmSailorfuku
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?

Re: seperating scripts into different files.

Posted: Tue Feb 26, 2008 6:21 am
by spaghett1
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:

Re: seperating scripts into different files.

Posted: Tue Feb 26, 2008 7:37 am
by Administrator
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.

Re: seperating scripts into different files.

Posted: Tue Feb 26, 2008 8:37 pm
by spaghett1
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. ;)