What file extension are you using for ModScript (i.e. Chaiscript) files?

What file extension are you using for ModScript (i.e. Chaiscript) files?

I'm currently using ".chai".  For AppScript I started using ".tsc" (i.e. "TeamScript") many years ago, along with ".tsl" for "Teamscript Library" files which are libraries of functions to be "included". 

Using ".msc" for "ModScript" might cause confusion because of the name collision with Windows "console" files.

  • 0  

    I use the chai extension as well.

    I've been using Visual Studio Code with the ChaiScript Syntax extension. It does a nice job with modscript code.

    I haven't used a different extension for our library of general functions. I have them in separate modscript files. I find some of the most used functions below:

    1. Get an selection id from a uuid:

    add_global_const(12, "CONST_TS_SELECTIONS");

    def GetSelectionIDByUUID( uuid ) {
      var rec = Ext.CreateAppRecord( CONST_TS_SELECTIONS );
      rec.ReadByUUID(uuid);
      return rec.GetId();
    }

    And then to extend vector for a contains call (which I can remember easily):

    def Vector::contains(token) {
        var vec = this;
          for (i:vec){
            if(i == token){
              return true;
            }
          }
          return false;
    }

    Then a call to return multi selection values back in an array:

    def TrimCommas( s ) {
        reverse( drop_while( reverse( drop_while( s, fun(x){ return x == ','; } ) ),
            fun(x) { x == ','; }));
    }

    def Field::GetValueMulti() {
      var arr = [];
      var s = TrimCommas(this.GetValueString());
      if(s == ""){return arr}
      else {
        var vals = s.split(",")
          for (i:vals){
            arr.push_back(i.trim_self().to_int());
          }
          return arr;
      }
    }

  • 0 in reply to   

    Nice.  Did you try any alternative methods for "TrimCommas", like "find_first/last_of" with "erase_at"?  I imagine the string.reverse operations are doing a lot of memory allocating and freeing.

    I'll admit that the one-line approach has advantages.

    I've been ignoring the SBM CSV strings for multi-X fields and been using the ts_Usages, ts_SelectionUsages and ts_MultiUserUsages tables.  When using AppScript or ModScript, SBM will take care of updating the CSV from the USAGES tables or vice-versa.  That's a nice feature.