String Table Shift

Hi All,

Recently I wanted a command something like ShiftNumTableElements but for a string table. I wanted to shift all the elements down by one to add the newest string at the top (the string is a message that’s part of a simple event log).

I thought about writing a subroutine with a loop, but I wanted something simple, quick, and easy to understand. So instead I decided to leverage the scratch pad area (for strings) which I wasn’t using anyway. My shift & update turned into just three lines of OptoScript code:

 
      // Read what's currently in the SP strings (so we can shift them down one)
      //GetIoUnitScratchPadStringTable(I/O Unit, Length, From Index, To Index, To Table)
      nSPResult = GetIoUnitScratchPadStringTable(R1, 63, 0, 1, stEventLog);
 
      // Load element [0] of the table
      stEventLog[0] = sLogMessage;
 
      // Write the updated log list to the scratch pad
      //SetIoUnitScratchPadStringTable(I/O Unit, Length, To Index, From Index, From Table)
      nSPResult = SetIoUnitScratchPadStringTable(R1, 64, 0, 0, stEventLog);

The last message in this “queue” drops of the end of both my stEventLog and the 64 strings (max length 124) in the scratch pad area of my mem map.

I’ll share the rest of my event log in another post here.

-OptoMary