The property identifier.
Optional
value: string | number | booleanData value of the property to set.
import { world, DimensionLocation } from "@minecraft/server";
function incrementDynamicProperty(
log: (message: string, status?: number) => void,
targetLocation: DimensionLocation
) {
let number = world.getDynamicProperty("samplelibrary:number");
log("Current value is: " + number);
if (number === undefined) {
number = 0;
}
if (typeof number !== "number") {
log("Number is of an unexpected type.");
return -1;
}
world.setDynamicProperty("samplelibrary:number", number + 1);
}
import { world, DimensionLocation } from "@minecraft/server";
function incrementDynamicPropertyInJsonBlob(
log: (message: string, status?: number) => void,
targetLocation: DimensionLocation
) {
let paintStr = world.getDynamicProperty("samplelibrary:longerjson");
let paint: { color: string; intensity: number } | undefined = undefined;
log("Current value is: " + paintStr);
if (paintStr === undefined) {
paint = {
color: "purple",
intensity: 0,
};
} else {
if (typeof paintStr !== "string") {
log("Paint is of an unexpected type.");
return -1;
}
try {
paint = JSON.parse(paintStr);
} catch (e) {
log("Error parsing serialized struct.");
return -1;
}
}
if (!paint) {
log("Error parsing serialized struct.");
return -1;
}
paint.intensity++;
paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits
world.setDynamicProperty("samplelibrary:longerjson", paintStr);
}
See
world.setDynamicProperty
Remarks
Sets a specified property on the world to a value.
Param: identifier
The property identifier.
Param: value
Data value of the property to set.
Throws
Throws if the given dynamic property identifier is not defined.
Example: incrementDynamicProperty.ts
Example: incrementDynamicPropertyInJsonBlob.ts