What you see
bad argument #2 to 'CreateUnit' (integer expected, got string)- Saving a Lua map crashes the editor, even with a
%only in a comment (before 2.0.4). bad argument #1 to 'I2S' (number has no integer representation)- Without an error handler, the trigger just stops partway.
Why it happens
FourCC. In JASS, 'hfoo' is an integer. In Lua it is a string, so object ids must be converted with FourCC('hfoo').
The percent sign. Before 2.0.4 the editor passed Lua code through a formatter that treats % specially, so a single % anywhere could crash it. Separately, DisplayTimedTextFromPlayer fills in only the first %s.
Integers. Lua's / always produces a decimal, so 7/2 is 3.5, and passing it where a native wants an integer fails. JASS integer division used to truncate.
Lua also needs patch 1.31 or newer, and the classic 1.29 client cannot run Lua maps at all.
How to fix it
- Wrap every object id in
FourCC('hfoo'), and cache them at the top of the script. - Update the editor to 2.0.4 or newer. Avoid
%in map Lua: usemath.fmodfor remainders and..to build strings, or write%%if you must. - Use
//for integer division, andmath.floorbefore calling a native that wants an integer. - While testing, add an error handler such as Debug Utils so a failing call shows a message.
How WC3 Map Doctor detects it
- SevereA Lua call passes a four-character string where an object id (integer) is expected, so the call errors and the trigger stops.LUA-fourcc-missing
- SevereThe Lua script contains a percent sign (even in a comment or string), which crashes the editor before 2.0.4.LUA-percent-pre-204
- ErrorsThe map uses Lua as its script language, which needs 1.31 or later.LUA-min-patch
- WarningsDisplayTimedTextFromPlayer replaces only the first %s, and a second one prints garbage or crashes Lua maps on 1.32.CRASH-displaytimedtext-percent-s
- ErrorsThe Lua script does not parse, and the game then shows no player slots and no log line.GATE-lua-parse
Sources
Written in our own words from our lab notes; these are the pages behind them.
- forumHive Workshop: A comprehensive guide to mapping in Lua
- publishedBlizzard: patch notes, version 2.0.4
- authorjassdoc: annotated common.j and Blizzard.j
- authorfixus issue 99: number has no integer representation
- forumHive Workshop: natives returning real instead of integer in Lua
- publishedLua 5.3 Reference Manual