setShared
Make a value shared across all scripts
Overview:
Functions:
API Reference
setShared()
setShared()Shares the value across all scripts
setShared("ExampleKey", "ExampleValue");Parameters:
key(String) The unique identifier for the variable.value(Any) The value to be shared.
Example:
// Function to broadcast the total entity count
function broadcastEntityCount() {
task.main(function() {
// Get the server and initialize entity count
var server = plugin.getServer();
var entityCount = 0;
// Get all worlds on the server
var worlds = server.getWorlds();
for (var i = 0; i < worlds.size(); i++) {
var world = worlds.get(i);
// Add the number of entities in the current world to the total count
entityCount += world.getEntities().size();
}
// Broadcast the total entity count to all players
server.broadcastMessage("Total entities: " + entityCount);
});
}
// Call the broadcastEntityCount function immediately
broadcastEntityCount();
// Set the broadcastEntityCount function as a public variable
setShared("broadcastEntities", broadcastEntityCount);Last updated
Was this helpful?