#hello world on server initialize?

1 messages · Page 1 of 1 (latest)

minor jolt
#
  const {dimension} = event;
  dimension.runCommandAsync(`say test world init`);
});```

I don't think I have the event -> object part correct. some events and objects have descriptions on the wiki but this one doesn't. 
https://jaylydev.github.io/scriptapi-docs/latest/classes/_minecraft_server_1_14_0.WorldInitializeAfterEventSignal.html

is there a way to get the dimension or a player or something I can run commands off of from the initialize event?
stiff patio
#
world.afterEvents.worldInitialize.subscribe(() => {
    for (const player of world.getAllPlayers()) {
        player.sendMessage("Hello, World!")
    };
})```
minor jolt
#

I'm trying to run a function ultimately

stiff patio
#

why worldinitialize though? 🤔

minor jolt
#

I use hello world as a proxy to get it working

#

to run once on world startup

stiff patio
#

oh

minor jolt
#

I can do on player join too, I was just curious if I could only do it once

stiff patio
#

which function is it

minor jolt
#

custom, it sets up scoreboard dummys

stiff patio
#

if its for scoreboard

#

then you prob dont even need dimension

#

world had scoreboard property

minor jolt
#

is world part of the world initialize event?

#

i'm still iffy on how to get those out of the event

#
  const {world} = event;
  world.runCommandAsync(`say test world init`);
});```
#

?

stiff patio
#

no you just do it like world.runCommand()

#

assuming youve already imported world from module

minor jolt
#

i didn't know that existed

#

thanks!

stiff patio
#

its basically what js import { world } from "@minecraft/server";
those are for

minor jolt
stiff patio
#

you can use world everywhere

minor jolt
#

I get the autofill in here but it isn't in the script api doccumentation

stiff patio
#

ough wait

#

i just realized world doesnt have runCommand

#

at this point you could just do js world.getDimension("overworld")

#

this returns overworld dimension you can use to run command

stiff patio
minor jolt
#

just a function

#

for future readers EDIT: the say command only works on reload but the function still runs even on startup. I don't think chat gets messages this early
world.getDimension("overworld").runCommand("say test world runcommand");

#

world.getDimension("overworld").runCommand("function setup");

#

🙂