Difference between revisions of "Loading Level Objects When Level Starts"

Jump to navigation Jump to search
Improved/moved note about avoiding object-order problems
m
(Improved/moved note about avoiding object-order problems)
Line 3: Line 3:
To do this, you can add code to the Lua functions which construct objects from their ...Instances tables, so that whenever the game calls those functions at the start of a level, new object constructors are inserted and/or existing objects are changed before the objects start getting constructed.
To do this, you can add code to the Lua functions which construct objects from their ...Instances tables, so that whenever the game calls those functions at the start of a level, new object constructors are inserted and/or existing objects are changed before the objects start getting constructed.
Another option is to add code to the embedded (Object Type)Instances.lua files themselves, and make them call a function which adds/edits level objects in the table or simply loads a completely new table from a non-embedded file. Some level object types seem to be built with currently-inaccessible C functions instead of Lua functions, and this might be the only way to change those tables.
Another option is to add code to the embedded (Object Type)Instances.lua files themselves, and make them call a function which adds/edits level objects in the table or simply loads a completely new table from a non-embedded file. Some level object types seem to be built with currently-inaccessible C functions instead of Lua functions, and this might be the only way to change those tables.
'''Important note-''' To avoid causing new glitches in your game, and ''especially'' to avoid causing them in the games of non-modding companions, new objects which weren't in the original game apparently need to:
*be inserted at the end of their (Object)Instances tables
*have ObjectNames that ''do not'' start with any numbers or the letters A through F (either uppercase or lowercase).
So for example instead of naming something "ABC" or "123", then name it at least "gABC" or "g123".
<div class="toccolours mw-collapsible mw-collapsed">
<div style="font-weight:bold;line-height:1.6;">Explanation</div>
<div class="mw-collapsible-content">
Further testing is needed, but it appears that some things in the game code look for objects based on the order they were created from the table and/or their place in the alphabetical order of ObjectNames, instead of just looking for the ObjectName in the Names table. This seems especially to happen when the game is sending updates about networked objects to your companion.
So, if your objects are ordered differently than they should be because you put something new into the middle of the ordered list, then stuff won't work right, for example because the game will try to activate "object # 50" but the correct object is now "object # 55", or because it's "object # 55" in your game but is "object # 50" in your companion's game.
Alphabetical order seems important, but if so then fortunately all the game's original ObjectNames are in hex, so they only contain numbers and the letters "a" through "f" - meaning that any new ObjectName starting with a letter after "f" will come in alphabetical order after all the original objects. (Technically anything after "ff" also works, like "fgName")
There is a chance that actually ''any'' new objects will disrupt some order and cause issues in online play if companion doesn't have the exact same objects, but tests done so far had no visible problems as long as the new objects were at the end of the table and had "safe" object names.
</div></div>


=Loading objects with Lua functions=
=Loading objects with Lua functions=
Line 430: Line 446:


*"Add" object constructors will create new, extra objects.
*"Add" object constructors will create new, extra objects.
**'''Please note''' that new objects made with Add tables should probably always have ObjectNames that don't start with numbers or letters before "g", so for example instead of naming something "Apple" then name it at least "gApple" or something:
**since number-alphabetical order references seem to be used for determining how some object-related stuff works (not sure yet though), and all the original ObjectNames are in hex so they start with numbers 0-9 or letters a-f, naming a new object like that seems to mess up the object order, which will likely cause level glitches during multiplayer and possibly also in solo play.
*"Edit" object constructors will replace the original constructor that has the same ObjectName, this can be used to change objects from the original game as well as new objects made with the "Add" tables.
*"Edit" object constructors will replace the original constructor that has the same ObjectName, this can be used to change objects from the original game as well as new objects made with the "Add" tables.


Navigation menu