User Tools

Site Tools


annotations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
annotations [2021/12/06 14:23] – created maximeannotations [2021/12/10 11:33] maxime
Line 8: Line 8:
  
 <code lua> <code lua>
-mod:createData({+foundation.createData({
  DataType = "BUILDING_PART_COST",  DataType = "BUILDING_PART_COST",
  ResourceNeededList = { -- list of RESOURCE_COLLECTION_VALUE  ResourceNeededList = { -- list of RESOURCE_COLLECTION_VALUE
Line 27: Line 27:
  }  }
 }) })
 +</code>
 +
 +=== Lazy-init ===
 +
 +By default, components are always initialized (call of ''init'' function) right after being created. For components flagged as //lazy-init// though, if the component is disabled on creation, the initialization is delayed until the component is enabled for the first time.
 +
 +<code lua>
 +local standardComp = nil
 +local lazyInitComp = nil
 +
 +level:createObject(function(_newObject)
 +    standardComp = _newObject:addComponent("STANDARD_COMPONENT")
 +    standardComp:setEnabled(false)
 +    
 +    lazyInitComp = _newObject:addComponent("LAZY_INIT_COMPONENT")
 +    lazyInitComp:setEnabled(false)
 +end)
 +-- at the end of createObject, only standardComp is initialized because it is disabled, but not lazy-init
 +
 +-- when enabling lazyInitComp, since it's enabled for the first time, it is initialized at the same time
 +lazyInitComp:setEnabled(true)
 </code> </code>
  
annotations.txt · Last modified: 2022/08/16 10:56 by maxime

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki