#How can I run code from a variable
1 messages · Page 1 of 1 (latest)
You should use eval function
Here there's a bit about how to use it, you should add capability to the bp manifest
import { world } from "@minecraft-server";
world.beforeEvents.chatSend.subscribe(chat => {
const msg = event.message
if (msg[0] !== ">") return
event.cancel = true
eval(msg.replace(">", ""))
})
Is there something that is like eval(“world.sendMessage(‘aaa’)”) or like a run thing
@iron valve m9 already gave you an example.
So I can just do eval(world.sendMessage())
no, it should be eval('world.sendMessage("test")')
just try the script m9 gave
remember that if you use a single quote eval('..') you could use a single quote in codes inside it anymore and vice versa
also when doing a statement, it requires a bracket
Ik
It needs to be !run codeGoesHere
How would I do that
Change > to !run simple as that.
what is eval() for btw
thanks
yeah.
eval is not defined
if (!msg.startsWith("!run")) return
``````js
eval(msg.replace("!run", ""))
ok
What does dw mean?