The scripting interface lets you run javascript code on your own server and send updates into the world. Everyone that connects to the world sees the same view of your scripted parcel. You can write scripts inside any feature on a parcel, and access other features from that script.
Once you own a parcel, you can start using the feature scripting engine. Scripting in cryptovoxels is mainly client based. That is, most scripts will be run by the client and not the server.
The hierarchy is:
For scripting examples: click here
This section includes properties, functions and events common to all plots.
ID - parcel.id
- Returns an integer; the parcel's id
getFeatures - parcel.getFeatures()
let features = parcel.getFeatures();
getFeatureById - parcel.getFeatureById(id)
let door = parcel.getFeatureById('door');
console.log('door:', door);
getFeatureByUuid - parcel.getFeatureByUuid(Uuid)
let feature = parcel.getFeatureById('3ed2bdd2-7570-485d-85b3-e5fd950bf3c6');
console.log('feature:', feature);
getFeaturesByType - parcel.getFeaturesByType(type)
let allVoxModels = parcel.getFeaturesByType('vox-model');
Valid types are:
'vox-model'
'button'
'image'
'sign'
'polytext'
'audio'
'nft-image'
'megavox'
'text-input'
createFeature - parcel.createFeature(type)
let newFeature = parcel.createFeature('vox-model');
When a feature is created it has a scale and position of [0,0,0].
Thus, remember to give it a position and a scale once created. To learn how to that, scroll down toFeature object > Properties
.
removeFeature - parcel.removeFeature(f)
let chair = parcel.getFeatureById('chairvox')
parcel.removeFeature(chair);
getPlayers - parcel.getPlayers()
Available from parcel.getPlayers()
or feature.on('click', e => console.log(e.player))
. Currently is just an object, but will become a class in the future.
player.name
=> 'captainbenis.eth'player.wallet
=> '0x2D891ED45C4C3EAB978513DF4B92a35Cf131d2e2'player.uuid
=> avatar uuid for this instance of the player (player may have multiple tabs open with seperate avatars)There are multiple ways to spoof
player.wallet
andplayer.name
, do not trust or send funds to this address. We will tighten up the security in the future for the grid server and update these docs when we do.
Player enter - parcel.on('playerenter', (e)=> {})
e
containing a player object with the player's information.e.player.name -> returns "Fayelure"
Player leave - parcel.on('playerleave', (e)=> {})
e
containing a player object with the player's information.e.player.wallet -> returns "0xdbw2fr8..."
move - player.on('move', (e)=> {})
This section includes properties, functions and events common to all features.
For feature-specific properties and methods, go to the features page in features.
ID - feature.id
feature.id = 'myvoxId'
Type - feature.type
Types include:
Position - feature.position
feature.position.set(1, 0.72, 2)
feature.position.y = 0.72
feature.set({position:[1,0.72,2]})
See scripting examples for Positions
Scale - feature.scale
feature.scale.set(0.75, 0.75, 0.75)
feature.scale.y = 0.75
feature.set({scale:[0.75,0.75,0.75]})
See scripting examples for scales.
Rotation - feature.rotation
set
on it eg: feature.rotation.set(0, 0, 0)
feature.rotation.y = 3.14
.feature.set({rotation:[0,3.14,0]})
See scripting examples for rotations.
While the in-world user interface uses degrees, the scripting engine uses radians.
3.14 (pi) will rotate the item 180 degrees.
nb: Position, scale and rotation are Vector3
object, with a ES6 proxy watching for updates to x
, y
and z
.
feature.position.x = 1
works.feature.position.copyFrom(new Vector3(1, 2, 3))
worksfeature.position.set(1, 2, 3)
works.feature.position.addInPlace(new Vector3(4, 5, 6))
worksfeature.position = new Vector3()
won't work.Description - feature.description
set
on the object.set
to update attributes in the description.clone() => Returns a clone
remove() => Remove feature from the parcel
set({ url: 'http://', ... }) => Set the properties of the feature
get('url') => Get the property of the feature
on click - Gets a click event. Only works on vox-model
and button
at the moment.
feature.on('click', (e)=> {
console.log(e.player) // Player object
console.log(e.point) // Vector3 of click in parcel space
console.log(e.normal) // Vector3 of normal at face where clicked
})
For feature specific properties, go to your desired feature and scroll down to Scripting Properties.