Level Script API: Difference between revisions

From DF21 Wiki
(→‎Methods: object getters)
 
Line 93: Line 93:
level.findConnectedSectors(mySector, 0, sectorList);
level.findConnectedSectors(mySector, 0, sectorList);
system.print("My sector has {} adjoining sectors", sectorList.length);
system.print("My sector has {} adjoining sectors", sectorList.length);
</pre>
=== getObject(int) ===
* Return value: Object
* Parameter: object Id (int)
=== getObject(string) ===
* Gets an object by its name. If there are multiple objects with the same name, the first one found will be returned.
* Return value: Object
* Parameter: object name (string)
* Usage example: <code>Object myobj = level.getObject("commando_13");</code>
=== getObjectsByName(string, array<Object>) ===
* Gets all objects with a given name into an array.
* Return value: void
* Parameters:
** name of objects to get (string)
** an array of objects that will be populated by the function
* Usage example: get all objects that have the name "squad"
<pre>
array<Object> mySquad;
level.getObjectsByName("squad", mySquad);
system.print("There are {} objects in the list", mySquad.length);
</pre>
</pre>

Latest revision as of 01:49, 30 August 2025

Documentation for TFE Level Script API.

Properties

minLayer

  • Get only
  • Gets the minimum map layer (signed integer)
  • Usage example: int i = level.minLayer;

maxLayer

  • Get only
  • Gets the maximum map layer (signed integer)
  • Usage example: int i = level.maxLayer;

sectorCount

  • Get only
  • Gets the total count of sectors (signed integer)
  • Usage example: int i = level.sectorCount

secretCount

  • Get only
  • Gets the total count of secrets (signed integer)
  • Usage example: int i = level.secretCount

textureCount

  • Get only
  • Gets the total count of textures (signed integer)
  • Usage example: int i = level.textureCount

elevatorCount

  • Get only
  • Gets the total count of elevators (signed integer)
  • Usage example: int i = level.elevatorCount

parallax

  • Get only
  • Gets the parallax (float2)
  • Usage example:
float2 pa = level.parallax;
float horzParallax = pa.x;
float vertParallax = pa.y;

gravity

  • Set only
  • Sets the level's gravity (int)
  • Usage example: level.gravity = 80;

projectileGravity

  • Set only
  • Sets the projectile gravity (int)
  • Usage example: level.projectileGravity = 60;

Special sector getters

bossSector

  • Gets the boss sector (Sector)
  • Usage example: Sector bossSect = level.bossSector;

mohcSector

  • Gets the mohc sector (Sector)
  • Usage example: Sector mohcSect = level.mohcSector;

completeSector

  • Gets the complete sector (Sector)
  • Usage example: Sector completeSect = level.completeSector;

Methods

getSector(int)

  • Return value: Sector
  • Parameters: sector Id (int)
  • Usage example: Sector mySector = level.getSector(14);

getSector(string)

  • Return value: Sector
  • Parameters: sector name (string)
  • Usage example: Sector mySector = level.getSector("door6");

getElevator(int)

  • Return value: Elevator
  • Parameters: elevator Id (int)
  • Usage example: Elevator myElev = level.getElevator(9);

findConnectedSectors(Sector, uint, array<Sector>)

  • Return value: void
  • Parameters:
    • the starting sector (Sector)
    • properties to match on (uint); see sector properties enum
    • an array of sectors that will be populated with sectors which are connected (adjoined) to the starting sector
  • Usage example: get sector 5, then get all the sectors adjoined to it
Sector mySector = level.getSector(5);
array<Sector> sectorList;
level.findConnectedSectors(mySector, 0, sectorList);
system.print("My sector has {} adjoining sectors", sectorList.length);

getObject(int)

  • Return value: Object
  • Parameter: object Id (int)

getObject(string)

  • Gets an object by its name. If there are multiple objects with the same name, the first one found will be returned.
  • Return value: Object
  • Parameter: object name (string)
  • Usage example: Object myobj = level.getObject("commando_13");

getObjectsByName(string, array<Object>)

  • Gets all objects with a given name into an array.
  • Return value: void
  • Parameters:
    • name of objects to get (string)
    • an array of objects that will be populated by the function
  • Usage example: get all objects that have the name "squad"
array<Object> mySquad;
level.getObjectsByName("squad", mySquad);
system.print("There are {} objects in the list", mySquad.length);