No announcement yet.

For Loops, Tables, and AutoPlay 8

  • Filter
  • Time
  • Show
Clear All
new posts

  • For Loops, Tables, and AutoPlay 8

    Since there have been a few posts about For loops in AutoPlay 8.0 here is a quick snippet from the help file that should help anyone having problems iterating over tables using for loops:

    AutoPlay Media Studio now contains an updated version of the Lua scripting library, version 5.1 (previously 5.0). AutoPlay's version has been compiled to try to maintain compatibility, however there are some minor syntax changes/deprecations made to the language that you need to be aware of for future development as well as previously created projects and lua scripts.

    When importing a project made with an earlier version of AutoPlay Media Studio, AutoPlay Media Studio 8 will automatically analyze your project file and create a report detailing any areas where it thinks the old style for loop is in use. If there are any old for loops found the report will automatically be saved in the same folder as your new 8 project file and opened in your default web-browser. We recommend analyzing each line of code found in the report to ensure that you only use the new for loop syntax.

    Table Iterating For Loops

    The syntax for iterating over a table using a for loop has changed (has been deprecated). If the new syntax is not used, a runtime error will be thrown when executed.

    Old syntax:

    mytable = {"One","Two","Three"};
    for k, v in mytable do
        Dialog.Message("Table Item", k .. "=" .. v);
    end -- for
    Needs to be changed to:

    mytable = {"One","Two","Three"};
    for k, v in pairs (mytable) do
        Dialog.Message("Table Item", k .. "=" .. v);
    end -- for
    The functions table.foreach and table.foreachi are also deprecated. You can use a for loop as above with pairs or ipairs instead. While these two are deprecated, they still work (unlike the example above), however you are advised to also rework these types of loops in case they are removed from future versions.

    If you commonly use Lua functions (non-AutoPlay actions) in your scripts, you may also want to review the list of other changes to the language in case other changes affect you. You can find this information in the Lua 5.1 Reference Manual found on, specifically the Changes in the Language section.

    Remember if you are going to iterate over a table in AutoPlay Media Studio 8.0 you will generally need to use the pairs function or less commonly the ipairs function.
    Last edited by Mark; 05-28-2010, 10:32 AM.
    MSI Factory The Next Generation Intelligent Setup Builder

  • #2
    Just a quick question on this. Has anybody actually seen one of these for loop reports?

    I've opened a number of older apz and have had to hunt and peck to find the for loops.

    Maybe I missed something, but then again...



    • #3
      Hi Dean,

      The report is and HTML file and will open in whatever program is set to handle those files automatically. I just ran a quick test in with a project form 7.5 and it worked however when testing with an apz file it seems as though the report was not generated. It looks like there may be a problem with the report when opening apz files. For now if you want to get the report, open the apz in AutoPlay 7, and then open the extracted project file in AutoPlay 8.

      Ref: AMS-499

      MSI Factory The Next Generation Intelligent Setup Builder


      • #4
        I saw the reports in version and (maybe) in

        In newest version the report disappeared.
        We are slowly invading your planet to teach lazy humans to read the user manual.
        But don't be scared: we are here to help.


        • #5
          I have seen the report several times in AMS 8.1 when opening some sample projects from this forum. I dont recal exactly which ones but it is nice that it informs users of the syntax changes.