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

Jump to navigation Jump to search
(→‎Example script: LoadModLevelObjects: clarification continued)
Line 443: Line 443:


Then create/assign tables of level object constructors inside the Mod.LevelObjects... tables, and the object changes will occur whenever a level loads.
Then create/assign tables of level object constructors inside the Mod.LevelObjects... tables, and the object changes will occur whenever a level loads.


'''Table usage'''
'''Table usage'''


The "main" tables are for the different functions of the script:
The "main" tables are for the different functions of the script:
Line 456: Line 458:
Each of these function-based tables includes object-type-based tables, with the type name used by their Instances table: for example Mod.LevelObjects.Add.Trigger is for adding Triggers to TriggerInstances.
Each of these function-based tables includes object-type-based tables, with the type name used by their Instances table: for example Mod.LevelObjects.Add.Trigger is for adding Triggers to TriggerInstances.


'c''Speifying levels to change'''
 
'''Specifying levels to change'''
 


The tables actually filled with object constructors are level-based, and are named like:
The tables actually filled with object constructors are level-based, and are named like:
Line 466: Line 470:
<code>Mod.LevelObjects.Add.Trigger["0.0"]</code>
<code>Mod.LevelObjects.Add.Trigger["0.0"]</code>


For tables that should load in all levels, use All/["All"] as the table key, for example:  
For tables that should load in all levels, use ["All"]/All as the table key, for example:  


<code>Mod.LevelObjects.Add.Trigger.All
<code>Mod.LevelObjects.Add.Trigger["All"]


Mod.LevelObjects.Add.Trigger["All"]</code>
Mod.LevelObjects.Add.Trigger.All</code>




You can simply build things in the main tables, running code like:
You can create these tables directly, running code like:


<code>Mod.LevelObjects.X.Y["Z"] = { Object1, Object2, Object3 }</code>
<code>Mod.LevelObjects.X.Y["Z"] = { Object1, Object2, Object3 }</code>


But it might be more convenient to store the tables elsewhere and just swap them around, like:
But it might be more convenient to "store" the tables elsewhere and assign them around, like:
  <nowiki>
  <nowiki>
Table1 = { Object1, Object2, Object3 }
Table1 = { Object1, Object2, Object3 }
Table2 = { Object4, Object5, Object6 }
Table2 = { Object4, Object5, Object6 }
Mod.LevelObjects.X.Y["Z"] = Table1
Mod.LevelObjects.X.Y["Z"] = Table1
-- Then later you swap it:
-- Then later you decide to swap it and do:
Mod.LevelObjects.X.Y["Z"] = Table2
Mod.LevelObjects.X.Y["Z"] = Table2
</nowiki>
</nowiki>


To make a level stop using any table for a function, run code like:
 
To make a level stop changing something, run code like:


<code>Mod.LevelObjects.X.Y["Z"] = nil</code>
<code>Mod.LevelObjects.X.Y["Z"] = nil</code>




You must format the tables a little differently from what is used in (Object Type)Instances.lua's, since this function uses strings of tables rather than actual tables (the only way I found so far to avoid errors with persistent tables).
'''Formatting object constructors'''
 


For example, (ObjectType)Instances tables are formatted like this:
You must format these tables a little differently from what is used in (Object Type)Instances.lua files, since this script uses strings for object constructors rather than actual tables (the only way I found so far to avoid errors with persistent tables, explained more in code comments).
 
For example, (ObjectType)Instances.lua files are formatted like this:
  <nowiki>SomethingInstances =  
  <nowiki>SomethingInstances =  
{ ObjectType = "SomethingInstances"
{ ObjectType = "SomethingInstances"
Line 505: Line 513:
}</nowiki>
}</nowiki>


'But' the Mod.LevelObjects tables must be formatted like 'this':
'''But''' the ModLevelObjects tables must be formatted like '''this''':
  <nowiki>ExampleTable =  
  <nowiki>ExampleTable =  
{ ExampleName1 = [[ ObjectName = "ExampleName1"
{ ExampleName1 = [[ ObjectName = "ExampleName1"
Line 519: Line 527:




Objects in Null tables can either be formatted the same as Add/Edit, or simply as:  
Null objects can either be formatted the same as Add/Edit, or simply as:  


<code>ExampleName = true</code>
<code>ExampleName = true</code>
Line 527: Line 535:




Note that this does not yet work for Hulls or Decoration Meshes. Also, in order to work for Particle Emitters and Sound Emitters, the embedded (thing)EmitterInstances.lua's need to be edited so that they appear like:
'''Object types that need more work'''
  (thing)EmitterInstances =
 
 
This script does not yet work for Hulls or Decoration Meshes, see code comments.
 
Also, in order to make it work for Particle Emitters and Sound Emitters, the embedded (thing)EmitterInstances.lua files need to be edited so that they read like:
  <nowiki>(thing)EmitterInstances =
  {  
  {  
  keep this table the way it is  
  keep the original table the way it is  
  }
  }
  LoadModLevelObjects("(thing)Emitter")
  LoadModLevelObjects("(thing)Emitter")</nowiki>
</div></div>
</div></div>


Navigation menu