// PSEUWOW DEF_SCRIPT STARTUP FILE

// this is for debugging which scripts are loaded
// set to false to disable output
SET,LoadDebug true

LOG *** DefScript StartUp [${@version_short}]...

// first, load all scripts in path 'scripts' with extension .def
SET,fcount ?{LGETFILES,scriptlist,def scripts}
LSORT scriptlist
LOG *** Loading ${fcount} script files.
// iterate over all files and load them; if counter i is equal to the amount of files we are done.
SET,i 0
SET,errors 0
LOOP
    IF ?{EQUAL,${i} ${fcount}}
        EXITLOOP
    ENDIF
    SET,fn ./scripts/?{LINDEX,scriptlist ${i}}
    IF ?{AND,?{IsSet LoadDebug} ${LoadDebug}}
        LOG * Loading script file [${fn}]
    ENDIF
    IF ?{NOT ?{LOADDEF ${fn}}}
        LOGERROR * Error loading [${fn}]
        ADD,errors 1
    ENDIF
    ADD,i 1
ENDLOOP

UNSET tmp
UNSET fcount
UNSET i
UNSET fn
LDELETE scriptlist

IF ?{NOT ${errors}}
    LOG *** All files loaded without errors.
ELSE
    LOG *** All files loaded, ${errors} errors.
ENDIF
UNSET errors

LOG *** StartUp complete!

