Class: World

Class contents

Methods list

These are special functions (or methods) that you may call on the object. these functions typically instruct the object to perform a certain operation.

Events list

Events are functions you add to your objects, that will be called by Cubiverse when certain things (events) occur.

Class Information

Constructor

new World()

You cannot instigate a World directly from normal Java-script code, it is created automatically by Cubiverse and varilable as the global WORLD variable.
Important:
  • You cannot instigate a World directly from normal Java-script code, it is created automatically by Cubiverse and varilable as the global WORLD variable.

Methods

createLight(x, y, z, visible, intensity, distance)

Creates a dynamic Light that can be modified in real-time

This command is used to create a dynamic light at the specified x,y,z world position. Each type of light has some common and some unique properties, for example the directional light has a target whilst the other lights do not. Please see for a full detais.

Performance Limitation : Be aware that each light has a large performance hit for a client; depending on your account you will be limited to 4, 8 or 16 lights per world. You should also try not to create lights in real-time, every time a light is created the clients must recalculate alot of information. This can cause "lag" on clients as the light is created (i.e. on slower clients they may notice a pause when the light is created, this can ruin the smooth rendering of the game). It is recommended that you create any lights when the world is first created. You can then move them, or change their color and intensity in real-time without any performance hit. {enum lightType The light to be created

lightType.ambient - An ambient light that lights all cubes ( remember that the "sun" in Cubiverse is made up of an ambient and directional light )

lightType.directional - A directional light, it accepts a target position to "point" towards ( remember that the "sun" in Cubiverse is made up of an ambient and directional light )

lightType.point - A point light, this emmits light from a central point.

Parameters:
Name Type Description
x float The x world position where the voxel is to be spawned
y float The y world position where the voxel is to be spawned
z float The z world position where the voxel is to be spawned
visible float Sets whether the light is initially spawned as "on"
intensity float Sets the intensity of directional and point lights
distance float Maximum distance (in units) from origin where light will shine whose intensity is attenuated linearly based on distance from origin (directional and point lights only)

Example
// Create a red light at x : 170, y : 13, z : 180 with a intensity of 3 and distance of 10 units
var myLight = WORLD.createLight( lightType.point, 170, 13, 180, true, 0xFF3333, 3, 10) ;

spawnItem(itemType, x, y, z)

Spawns an in-game item at the specified position

This command is used to spawn the specified item at the world position. If the object cannot be spawned you will be returned an "undefined" value, use this to check whether the object was spawned correctly.

Rate Limited: Please note spawning items is rate limited, depending on your account you will be able to spawn only a certain amount of items per server "tick" and you will be limited in the total number of items available in your world. You (and your players) will receive an exception and an "undefined" value in this case.

User Pickup: Users will be able to pick up any item spawned in the world, if you require multiple or unique items per user you will have to create this programatically.

Parameters:
Name Type Description
itemType enum The item to be spawned

userItem.torch - This item is a torch will projects a light infront of the player when activated

userItem.gravityTool - This item is a gravity tool which allows players to move cubes (not tested, definately not really supported in multiplayer)

userItem.pistolGun - A simple pistol gun, ammo and abilities are set on the object returned by the create

x float The x world position where the item is to be spawned
y float The y world position where the item is to be spawned
z float The z world position where the item is to be spawned

Example
var myTouch = WORLD.spawnItem( userItem.torch, 50.5, 20.5, 119.0 ) ;

spawnMob(x, y, z)

Spawns a zombie mob at the given position

This will spawn a zombie mob at the selected x,y,z world position. Please make sure that the zombie is not spawned inside cubes and that it has enough room to move. Secondly the zombie may not appear immediately, as before it can be spawned the server has to calculate its path to any target (by default this is any player), until this path is calculated the zombie is not visible. The zombie will then be spawned on top of the first cube directly below the world position you specify. You (and your players) will receive an exception and an "undefined" value in this case.

Rate Limited: Please note spawning mobs is rate limited, depending on your account you will be able to spawn only a certain amount of zombies per server "tick" and you will be limited in the total number of zombies available in your world. You (and your players) will receive an exception and an "undefined" value in this case.

Parameters:
Name Type Description
x float The x world position where the voxel is to be spawned
y float The y world position where the voxel is to be spawned
z float The z world position where the voxel is to be spawned

Example
var myMob = WORLD.spawnMob( 50,5,50 ) ;

spawnVoxel(x, y, z, voxelType)

Spawns an dynamic voxel (unconnected with any static voxels) at the specified position, of the specified type

This command is used to spawn a dynamic voxel at the specified x,y,z world position. As the voxel is purely dynamic is does not remove any static voxel, instead it is simply added to the world. It should be noted that whilst there is no limit on the number of voxels you can spawn, the available computing power of your world will be reduced with every voxel created (as it needs to be simulated, moved, events thrown, etc.)

Rate Limited: Please note voxels is rate limited, depending on your account you will be able to spawn only a certain amount of voxels per server "tick" and you will be limited in the total number of spawnable voxels in your world. You (and your players) will receive an exception and an "undefined" value in this case.

Parameters:
Name Type Description
x float The x world position where the voxel is to be spawned
y float The y world position where the voxel is to be spawned
z float The z world position where the voxel is to be spawned
voxelType voxelType The type of voxel to be spawned (must be > 0)

Example
var myVoxel = WORLD.spawnVoxel( 5, 10, 5, voxelType.grass ) ;

Events

OnItemDropped

Called when a player drops up an in-game item [Not supported]

This event is trigger when any player drops any item [Not supported Yet]

Parameters:
Name Type Description
itemObject object The actual BaseItem object that was dropped up by a player
playerObject object The actual playerObject who dropped it
Example
// Print some information when a player drops an item
WORLD.OnItemDropped = function( itemObject, playerObject )
{
    log("WORLD.OnItemDropped() called with item : " + itemObject.type + " by nick : " + playerObject.nickName) ;
}

onItemEquipped

Called when a player equips an item (but does not use it)

This event is trigger when an item is equipped by a player, it does not signal that they have used it (i.e. shot a gun, turned on the torch, etc.)

Parameters:
Name Type Description
itemObject object The actual BaseItem object that was equipped up by a player
playerObject object The actual playerObject who equipped the item
Example
// Print some information when a player equips an item
WORLD.onItemEquipped = function( itemObject, playerObject )
{
    log("WORLD.onItemEquipped() called with item : " + itemObject.type + " by nick : " + playerObject.nickName) ;
}

onItemEquipped

Called when a mob is spawned into the world

This event is trigger when an mob is spawned, either through a mob spawn points or using the spawnMob() API call.

Parameters:
Name Type Description
mobObject object The actual mobObject who was spawned
Example
// Print some information when a player equips an item
WORLD.onMobSpawned = function( mobObject )
{
    log("WORLD.onMobSpawned() called with item" + modObject.id ) ;
}

onItemEquipped

Called when a mob is removed into the world

This event is trigger when an mob is removed from the world, the mob is only removed after it's dead animations and fade out has occured. The mob is removed from the world after this call so you must not call any operations on the mob (and disregard the reference)

Parameters:
Name Type Description
mobObject object The actual mobObject who was removed
Example
// Print some information when a player equips an item
WORLD.onMobDead = function( mobObject )
{
    log("WORLD.onMobDead() called with item" + modObject.id ) ;
}

onItemPickedUp

Called when a player picks up an in-game item

This event is trigger when any player picks up any item

Parameters:
Name Type Description
itemObject object The actual BaseItem object that was picked up by a player
playerObject object The actual playerObject who picked it up
Example
// Print some information when a player picks up something
WORLD.onItemPickedUp = function( itemObject, playerObject )
{
    log("WORLD.onItemEquipped() called with item : " + itemObject.type + " by nick : " + playerObject.nickName) ;
}

onItemUnequipped

Called when a player unequips an item (but does not use it)

This event is trigger when an item is unequipped by a player, it does mean it's been dropped - just not in the players "hand"

Parameters:
Name Type Description
itemObject object The actual BaseItem object that was unequipped up by a player
playerObject object The actual playerObject who unequipped the item
Example
// Print some information when a player equips an item
WORLD.onItemUnequipped = function( itemObject, playerObject )
{
    log("WORLD.onItemUnequipped() called with item : " + itemObject.type + " by nick : " + playerObject.nickName) ;
}

onPlayerDead

Called when a player dies the world.

This event is trigger when any player dies (regardless of the reason) in the world.

Parameters:
Name Type Description
playerObject object The actual playerObject who has died
Example
// Print the player nickName to the debug console when a player dies
WORLD.onPlayerDead = function( playerObject )
{
    log("WORLD.onPlayerDead() called with nick : " + playerObject.nickName) ;
}

onPlayerJoined

Called when a player joins the world

This event is trigger when any player joins the world, it's a good way to store or handle a player joining the world. If you add the playerObject to some sort of array (i.e. to know all the connected players), remember to use the onPlayerLeave event to forget about the player

Object Presistance: The playerObject will persist until the player leaves (onPlayerLeft) or the world is killed. DO NOT use it after the player has left.

Parameters:
Name Type Description
playerObject object The actual playerObject that has joined the world
Example
// Print the player nickName to the debug console when the player joins
WORLD.onPlayerJoined = function( playerObject )
{
    log("WORLD.onPlayerJoined() called with nick : " + playerObject.nickName) ;
}

onPlayerLeft

Called when a player leaves the world

This event is trigger when any player leaves the world, normally this is used to remove the reference to the playerObject (should you have stored all joining players, for example in some sort of array).

Object Presistance: It is critical that you never reference the playerObject after this function completes as it will be undefined and completely invalid, and you may kill your world!

Parameters:
Name Type Description
playerObject object The actual playerObject that has entered the zone
Example
// Print the player nickName to the debug console when the player leaves
WORLD.onPlayerLeft = function( playerObject )
{
    log("WORLD.onPlayerLeft() called with nick : " + playerObject.nickName) ;
}

onPlayerSpawned

Called when a player spawns the world, this can happen if they join or respawns after dying

This event is trigger when any player joins the world and is first spawned but is most often called when a player respawns after dying!

Parameters:
Name Type Description
playerObject object The actual playerObject that has spawned
Example
// Print the player nickName to the debug console when a player spawns
WORLD.onPlayerSpawned = function( playerObject )
{
    log("WORLD.onPlayerSpawned() called with nick : " + playerObject.nickName) ;
}