#Help on detecting effects, how to use.
1 messages · Page 1 of 1 (latest)
not valid
if (entity.getEffect('invisibility')) {
console.warn('Entity: ' + entity.typeId + ' is invisible');
};
import { system, world } from "@minecraft/server";
function onTick() {
const allDimensions = [ 'overworld', 'nether', 'the_end' ];
for (const dimension of allDimensions) {
const entities = world.getDimension(dimension).getEntities();
for (const entity of entities) {
if (entity.getEffect('invisibility')) {
console.warn('Entity: ' + entity.typeId + ' is invisible');
};
};
};
};
system.runInterval(onTick);
well
wait
ima try what you sent me
what does this line means?
for (const dimension of allDimensions)```
Unless ur trying to get entities in a single dimension (overworld), you need that
@ancient hearth thanks A lot man
it works now
I am still bad at assigning things in JS cause im new
I now understand why they say Lua is a easy language
I have question though why
const allDimensions = [ 'overworld', 'nether', 'the_end' ];
for (const dimension of allDimensions)
do this?
assigning a constant to a constant? im a bit confused and it's using a for loop, why?
can you enlighten me about it?
to use getEntities(), you need a dimension, and you need to do it for each of the dimensions available
const allDimensions = [ 'overworld', 'nether', 'the_end' ];
just defines an array with all dimensions
for (const dimension of allDimensions) {
};
goes through each item in that array and for each item it creates a dimension variable which is holding it's value
you can skip this if you don't want ur script to function in nether or the end, in that u can simply just do this:
const entities = world.getDimension('overworld').getEntities();
for (const entity of entities) {
if (entity.getEffect('invisibility')) {
console.warn('Entity: ' + entity.typeId + ' is invisible');
};
};
so that for loop kind of converts it or re assigns it individually?
not convert, it's taking items from array and adding it on a variable
okay thanks a lot
so the reason you've got to put the array in a variable because you can't assign that array to the getDimenstion() function?
I kind of get how it works now