#Set World Dynamic Property

1 messages · Page 1 of 1 (latest)

white blaze
#

I want to set a dynamic property for world. I already know how to register the dynamic property for world. But, now I need to set the dynamic property and I'm confused what event do I have to set the dynamic property to.

Should I set the World Dynamic Property outside of one of the world event or inside of one of the world event?

quartz schooner
#

You can set anywhere

#

world.event is one way to run code

#

you can run it on system.runInterval or something

white blaze
#

should it be like this?

const worldData = 'worldData'

world.events.worldInitialize.subscribe((eventData) => {
    const propertyRegistry = eventData.propertyRegistry

    let worldDataDefinition = new mc.DynamicPropertiesDefinition();
    worldDataDefinition.defineString(worldData, 1000)
    propertyRegistry.registerWorldDynamicProperties(worldDataDefinition);
})

let worldDD = world.getDynamicProperty(worldData)
if (!worldDD) {
    worldDD = {
        eventStarted: false
    }
}
if (typeof worldDD == 'string') worldDD = JSON.parse(worldDD)
const { eventStarted } = worldDD

to set the dynamic property of the world?