CraftStudio Wiki

Scripting Reference/Map

< Scripting Reference

56pages on
this wiki
Add New Page
Comments3 Share


Returns A block ID between 0-254 if a block exists at the given location (all valid block IDs are in the range 0-254), otherwise If there is no block at the given location then it will return Map.EmptyBlockID (which has a value of 255).

[number] Map:GetBlockIDAt(
    [number] x,
    [number] y,
    [number] z


Returns The BlockOrientation of the block at the specified location, otherwise if there is no block at the given location it will return Map.BlockOrientation.North.

[BlockOrientation] Map:GetBlockOrientationAt(
    [number] x,
    [number] y,
    [number] z


Sets a block's ID and BlockOrientation at the given position on the map.

    [number] x,
    [number] y,
    [number] z,
    [number] block id,
    [BlockOrientation] orientation

Example: Setting and Getting a block IDEdit

function Behavior:Awake()
    local map = self.gameObject:GetComponent ("MapRenderer"):GetMap()

    -- We set the block at 5, 5, 5 to block ID 0
    map:SetBlockAt (5, 5, 5, 0, Map.BlockOrientation.East)

    -- We get the block ID at 5, 5, 5 which is 0
    local blockID = map:GetBlockIDAt (5, 5, 5)
    print (blockID)
    -- Outputs: 0


GetPathInPackage returns the full path of a map in the form of "Folder/Sub-folder/Asset name". For an example, see Map.LoadFromPackage.

[string] Map:GetPathInPackage()


LoadFromPackage returns a new copy of the map asset at the specified path. It's useful if you want to load a map from its original, saved state. You can destroy the new map later on by calling CraftStudio.Destroy on it

[Map] Map.LoadFromPackage( [string] path_of_map_in_gamepackage )

Example: Replacing a map with the original version in a map rendererEdit

function Behavior:Awake()
    -- Get the currently displayed map
    local mapRndr = self.gameObject:GetComponent( "MapRenderer" )
    local mapPath = mapRndr:GetMap():GetPathInPackage()
    -- Load a copy of the original version from the game package
    local newMap = Map.LoadFromPackage( mapPath )
    -- Display the newly loaded version of the map
    mapRndr:SetMap( newMap )

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.