CraftStudio Wiki
CraftStudio Wiki

Map:GetBlockIDAt[]

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
)

Map:GetBlockOrientationAt[]

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
)

Map:SetBlockAt[]

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

Map:SetBlockAt(
    [number] x,
    [number] y,
    [number] z,
    [number] block id,
    [BlockOrientation] orientation
)

Example: Setting and Getting a block ID[]

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
end

Map:GetPathInPackage[]

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()

Map.LoadFromPackage[]

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 renderer[]

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 )
end