Skip to content

Commit

Permalink
Update registerWorldDynamicProperties.js
Browse files Browse the repository at this point in the history
  • Loading branch information
defowler2005 authored Nov 3, 2023
1 parent e7c82bb commit 2741a80
Showing 1 changed file with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
import { DynamicPropertiesDefinition, world } from "@minecraft/server";

world.afterEvents.worldInitialize.subscribe(({propertyRegistry}) => {
// add boolean dynamic property
const dynamicProperty = new DynamicPropertiesDefinition();
dynamicProperty.defineBoolean("my_boolean");

// add number dynamic property
dynamicProperty.defineNumber("my_number");

// add string dynamic property
dynamicProperty.defineString("my_string", 256);

// register to world
propertyRegistry.registerWorldDynamicProperties(dynamicProperty);
});
import { world } from '@minecraft/server';

// Set dynamic property value
world.setDynamicProperty("my_boolean", true);
world.setDynamicProperty("my_number", 100);
world.setDynamicProperty("my_string", 'Hi mom');
world.setDynamicProperty('my_boolean', true);
world.setDynamicProperty('my_number', 100);
world.setDynamicProperty('my_string', 'Hi mom');

world.getDynamicProperty("my_boolean"); // true
world.getDynamicProperty("my_number"); // 100
world.getDynamicProperty("my_string"); // 'Hi mom'
world.getDynamicProperty('my_boolean'); // true
world.getDynamicProperty('my_number'); // 100
world.getDynamicProperty('my_string'); // 'Hi mom'

0 comments on commit 2741a80

Please sign in to comment.