Skip to content

Common pitfalls and unexpected behaviours

Matthew edited this page Feb 17, 2019 · 3 revisions

This is a list of weird behaviors that have caused unexpected issues.

  • Don't use local refs to global in control stage code

Refs to global table entries get broken during on_load which will cause desyncs.

  • Events will not be caught by modules until after on_init is complete

If you register an event in the control stage of x.lua and in y.lua raise an event during on_init, x.lua's event hook will not get triggered.

  • Dynamic requires

RedMew uses a script to deflate saves. This script does not work correctly with "dynamic requires", or require statements that use variables in them. Example: require 'map_gen.maps.' .. map_name

  • Printing table refs

Printing refs to tables has a high chance of causing desyncs. Ex. game.print(tostring(global)) or game.print(serpent.block(_ENV))

  • Setting speed

Cars can have their speed set by LuaEntity.speed however trains cannot. For trains you must use LuaEntity.train.speed. This can be tricky if you're using LuaPlayer.vehicle since you don't know what type of vehicle they might be driving.

Clone this wiki locally