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:
Needs to be changed to:
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 http://www.lua.org, 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.
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:
Code:
mytable = {"One","Two","Three"}; for k, v in mytable do Dialog.Message("Table Item", k .. "=" .. v); end -- for
Code:
mytable = {"One","Two","Three"}; for k, v in pairs (mytable) do Dialog.Message("Table Item", k .. "=" .. v); end -- for
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 http://www.lua.org, 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.
Comment