allocscript, loadscript, compilescript, executescript

Piccolo

Well-known member
I'm trying to use these functions to avoid loading some scripts files at the start of the game.

But can't get them to work, even with a simple script file.

Anyone ever tried to use those ? Are they broken ?
 
Piccolo said:
I'm trying to use these functions to avoid loading some scripts files at the start of the game.

But can't get them to work, even with a simple script file.

Anyone ever tried to use those ? Are they broken ?

Try this one (not mine):

Code:
void prepareScript()
 {
         void snumber        =        0;
         void sh;
         void i=0;
         /***********************************
                         Register Scripts Here
         ***********************************/
         void file=openfilestream("data/scripts/updated/s"+i+".c");
         while(file!=-1)
         {
                 snumber++;
                 i++;
                 closefilestream(file);
                 file=openfilestream("data/scripts/updated/s"+i+".c");
         }
         if(snumber)
         {
                 sh=array(snumber);
                 //
                 for(i=0;i<snumber;i++)
                 {
                         set(sh,i,allocscript("script"+i));
                         loadscript(get(sh,i),"data/scripts/updated/s"+i+".c");
                         compilescript(get(sh,i));
                 }
                 setlocalvar("script",sh);
         }
 }

 void execs()
 {
         void s,i;
         s=getlocalvar("script");
         if(!s)return;
         for(i=0;i<size(s);i++)
         {
                 executescript(get(s,i));
         }
 }
 void frees()
 {
         void s=getlocalvar("script");
         if(s)free(s);
 }
 
Thanks WD, but do you also have an example of the content of one of those "data/scripts/updated/s"+i+".c" (or the name of the mod this code is from)

Their content might tell me why I can't get mine to work as I use a similar code.


EDIT : ok I just tested to add a void main(){ } in the loaded script file and it works. Seems you can't pass & return variables to/from these called "sub"-scripts, so if you want to pass & get back some stuff they did in your calling "main"-script, use indexedvars.
 
Back
Top Bottom