LogoLogo
  • Introduction
  • sdks
    • Feature Comparison
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Quick Start
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Server Side
    • Entities
    • Chunks
    • Dimensions
    • Events
    • Logging
    • Lua Environment
    • Git Primer
    • Physics
  • HTTP API
    • Authentication
    • Player API
  • Api Reference
    • Entity API
      • Create
      • Message
    • Client API
      • Message
    • Dimension API
      • Create
      • Delete
      • List
    • Events API
      • on_player_join
      • on_player_leave
    • Table API
      • Append
      • Remove
      • Join
    • Util API
      • Time
      • TimeMillis
    • HTTP Request API
      • Get
      • Post
      • Put
      • Delete
    • Physics API
      • NewBody
      • NewBoxShape
      • NewSphereShape
Powered by GitBook
On this page
  1. Api Reference
  2. Dimension API

List

api.dimension.List()

Get all dimension IDs created for this game in a table.

The list does not include the default dimension, which has the ID of an empty string ("").

Returns:

Type
Description

string[]

An indexed string array of all dimension IDs which have been created.

Example:

List five dimensions which have been created and delete them according to their name.

-- init.lua
function init()
    if not chunk.Generated then
        if chunk.X == 0 and chunk.Y == 0 then
            local dimension_descriptions = {"Fun", 
                                    "Sleepy", 
                                    "Fluffy", 
                                    "Curious", 
                                    "Cuddly"}
            local first_letter
            local first_letter_compare
            local dimension_list 
            local remove_list
        
            if chunk.Dimension == "" then                                  
                for index, description in pairs(dimension_descriptions) do 
                    api.dimension.Create(description.." Catland")
                end    
            else
                first_letter = string.sub(chunk.Dimension,1,1)
                dimension_list = api.dimension.List()
                remove_list = {}
                
                for index, dimension_id in pairs(dimension_list) do
                    first_letter_compare = string.sub(dimension_id, 1, 1)                	
                    if first_letter == first_letter_compare then
                        remove_list = api.table.Append(remove_list, dimension_id)
                    end
                end
                          
                for index, dimension_id in pairs(remove_list) do 
                    api.dimension.Delete(dimension_id)
                end               
            end         
            print("The remaining dimensions are", api.dimension.List())               
        end
        
    end
end

-- When the chunk at the origin of the default dimension loads for the first time,
-- create a five dimensions, each named with a description of Catland.
-- When the chunk at the origin of a created dimension loads for the first time,
-- delete this dimension and any others starting with the same letter.

-- Prints (order varies):
-- The remaining dimensions are [Fun Catland Sleepy Catland Fluffy Catland Curious Catland Cuddly Catland]
-- The remaining dimensions are [Fun Catland Sleepy Catland Fluffy Catland]
-- The remaining dimensions are [Sleepy Catland]
-- The remaining dimensions are []

PreviousDeleteNextEvents API

Last updated 3 months ago