#Script API General

1 messages ยท Page 129 of 1

haughty kernel
#

Hmm... okay... it's a shame there isn't a beforeEvents page for this event.

warm mason
haughty kernel
honest spear
#

Hello everyone

zinc breach
#

if a player is on the death screen does checking player.isValid return false?

#

want to use a title command

snow knoll
zinc breach
#

because I'm pretty sure title commands fail if youre on the death screen

#

how about health component actually

snow knoll
#

Not entirely sure ๐Ÿค”
Not very familiar with the component or the command tbh

zinc breach
#

I'll test it out later but it should work

#

does player.setDynamicProperty() work even if the player is not valid

zinc breach
#

and is there a way to make an entity aggressive to a specific entity only? so say make a zombie aggressive to a spawned chicken or something

cold grove
#

Even With instant respawn i have to wait 1 tick

zinc breach
# cold grove Not valid
            let virusTicks = 0;
            system.runTimeout(() => {
                const virusInterval = system.runInterval(() => {
                    if (victim.isValid || virusTicks > 60) {
                        system.clearRun(virusInterval);
                    }
                    virusTicks++
                },10)
            }, 200)
#

this should run only when they respawn then right

cold grove
#

You can use playerSpawn event

zinc breach
zinc breach
#

this just checks to see if theyre valid every 10 ticks and if they are then that means they respawned

cold grove
#

I recommend to use playerSpawn

zinc breach
#

this is for an ability function tho I'm trying to keep it all in there

cold grove
haughty kernel
fringe hound
#

Yo anyone wanna work on my realm with me? (I'm not dead weight I could do it myself and have actually it's done now and my friends and I play on it currently) But none of them program or make addon so I'm looking to make friends with someone with skills like mine so we can make new exciting content for the realm. We're working with some cool systems such as: a magic way, and dorios RPG core (which allows us to make and register our own trinkets. I'm currently working on some atm) I would prefer if you can build comfortably as well as we're trying to make a nice city on the realm and don't need anymore cave house people lol. Let me know if you're interested and we can talk about details!

#

^must have PC and mic

#

Should mention my skills too: I can script comfortably (I've ran into enough problems know I can work things out if need be) and can do any of the other things an addon needs like items, feature rules, loot tables, entity behavior. Im not a very good artist tho full disclaimer lol.

fallow minnow
#

FINALLY

{"owned":[12],"selected":[12]}
#

is this a good way to do it?

#

numerical id based

supple perch
supple perch
#

You're gonna need a 5 bit integer tho since you have 20 ranks

supple perch
#

it's complicated tho so yeah

#

but I'm sure you can find enough tutorials on youtube or smth like that

fallow minnow
#

so like

1 - 99, chat ranks
100 - 199 capes / wings etc
200 - 299 hats / misc

#

or however else i do it

supple perch
#

even better

#

you should

fallow minnow
#

but question what does it actually like

supple perch
#

but yeah you'll definitely use a massive amount of bits prolly

fallow minnow
#

do

#

and wouldnt it take up more space?

supple perch
supple perch
#

it's js a number

#

literally that's it

#

gimme a sec

fallow minnow
#

but like

#

would i make the ids bit masks?

#

or

supple perch
#

I'm not too familiar with like performance differences of access in an array and in an object

fallow minnow
#

well tbf i am only updating when they change another one, and its just stored in the memory as cache

#

so i imagine its super fast stil

supple perch
#

but you can use js const obj = { 0: ///, 1: ///, };

or

const obj = [
  ///
  ///
];```
and use `obj[idx]`
supple perch
#

but if you ever need persistence

#

you might want to look into bitmasks

#

stringifying or just serializing in general isn't good since you store alot of data

fallow minnow
#

i dont stringify

supple perch
#

but it's unavoidable, but for certain things like flags, indexes, etc. you can use bitmasks

fallow minnow
supple perch
fallow minnow
#

oh

#

i dont really care about size as well

supple perch
fallow minnow
#

its getting sent to a postgreSQL database

supple perch
#

it's about, nvm

#

well idk if I'd do that tbh

#

but oh well

fallow minnow
#

do what

supple perch
#

not that it's bad

#

it's just kinda inconvenient

fallow minnow
#

nooo

#

i mean

#

so

#

im just storing which ones they own db side

#

and which one they have equipped

#

ill need it for later on indexing and counting up how many exist

supple perch
#

i was talking about like the general issues like if the external server were to go down

#

or bad internet

#

yes you can guard such systems

#

but basically it's inconvenient for the players to have to wait for everything to get back

fallow minnow
#

i dont think it will ever go down to be fair

supple perch
#

but that's only at the worst case

supple perch
fallow minnow
#

and their data is cached upon joining

supple perch
#

I'm just saying

fallow minnow
#

so im not just grabbing from the database each time

supple perch
#

just my opinion, I'm not judging lol

#

you can do whatever you want to, it's your server dude

fallow minnow
#

its just a locally hosted postgreSQL database through docker, which i read and write to from script api

fallow minnow
supple perch
#

which part of it don't you understand?

#

the actual ops?

#

or the why?

fallow minnow
#

yeah that and like where would i actually use it?

fallow minnow
#

would i store each rank in a bitmask?

#

or

supple perch
#

firstly do you know binary?

#

or should i explain it?

fallow minnow
#

i do not ๐Ÿ˜ญ

supple perch
#

since bitmasking heavily relies on it

supple perch
#

I'll make a quick drawing

#

and then explain

#

okay my drawing app is broken

#

I'll just have to settle for this representation

#

[8][4][2][1]
[0][0][0][0]

#

alright so this is the binary representation of 0, pretty simple

#

the numbers on the top are like, imagine them as a value only there when it's one

#

[8][4][2][1]
[0][0][1][1]

#

this is 3

#

basically bits are each switch

#

like one bit, is one switch

#

0 is off

#

1 is on

#

we add the numbers on the top of the switchs that are on

supple perch
#

2^idx

#

so for the first bit, it's value is 2^0, which is 1

#

the second bit it's 2^1 which is 2

#

and so on

fallow minnow
#

ohhh okok

#

so

supple perch
#

any questions so far?

fallow minnow
#

i understand it a little bit

supple perch
#

what part do you need help with

fallow minnow
#

so an idea would be to store owned cosmetics as a bitmap

#

i generated a number

#

i basically convert the ids to bitmap type thingy

supple perch
#

yea kinda..

fallow minnow
#

1073741823 is ids 1 - 30

supple perch
#

what

fallow minnow
#

like that?

supple perch
#

no

#

well

#

actually now that i think about it

#

telling you to use a bitmask for storing the selected rank ids is dumb

#

because you can select many IDs that are big in number

fallow minnow
#

isntead of having an array like

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]```

i could just simplify it down to 1073741823
supple perch
#

that could probably reach a big number that'd need bigint

supple perch
#

it's better if you had a set number of slots like say 3 slots for example, that'd be much more useful in that case

fallow minnow
#

wdym?

supple perch
#

or actually nvm you can use like a Uint8Array or something

fallow minnow
#

like this

function getOwnedRanks(mask, maxRank) {
    const owned= [];

    for (let id = 1; id <= maxRank; id++) {
        const bit = BigInt(id - 1);
        if ((mask & (1n << bit)) !== 0n) {
            owned.push(id);
        }
    }

    return owned;
}

const mask = 1073741823n;
console.log(getOwnedRanks(mask, 99));``` returns the array of which ranks i have from the mask number
supple perch
# fallow minnow wdym?

sorry I'm still learning binary myself too, your case requires a bit of thought since it's alot of big numbers like 30 and more

fallow minnow
#
[
   1,  2,  3,  4,  5,  6,  7,  8,  9,
  10, 11, 12, 13, 14, 15, 16, 17, 18,
  19, 20, 21, 22, 23, 24, 25, 26, 27,
  28, 29, 30
]
#

thats actually kinda cool

supple perch
fallow minnow
#

it seems very nice for storing data like that

supple perch
#

i recommend asking a professor or like watching a tutorial

#

or even an LLM explaining

supple perch
#

i gtg

#

good luck on learning!

#

and on your server

#

cya

fallow minnow
#

cya! thanks for explaining that to me its pretty cool

buoyant canopy
#

is this the optimal binary search ?

const count_items = (entity, item, guess) => {
    const command = (count) => `testfor @s[hasitem ={location=slot.weapon.mainhand, item=${item}, quantity=${count}}]`
    const check = (count) => entity.runCommand(command(count)).successCount
    if (guess && check(guess)) return guess
    let low = 1, high = 64
    while (low != high) {
        let mid = (low + high) >>> 1
        if (check(`..${mid}`)) high = mid
        else low = mid + 1
    }
    return low
}
distant tulip
slow walrus
#

but otherwise yeah, that's optimal

#

I would also add > 0 after the successCount in check, cause rn you're returning a number

#

doesn't make a difference in the if but it's clearer

remote oyster
#

How frequently is count_items being called?

round bone
#

How long is PlayFabId of a player?

buoyant canopy
#

how would the entity have 0 items?

#

i don't get it?

#

this is for entities not for players, it will only run when the script determines that the entity has a specific item in its main hand, so i can't be 0

round bone
buoyant canopy
fallow minnow
dusky flicker
#

since the id is linear

round bone
dusky flicker
round bone
#

He has to remove id field and calculate it with by an index

dusky flicker
#

instead of everything being hardcoded

dusky flicker
#

like

let id = registry.register("Red", "red", "static");
//now you use the id for the operations

fallow minnow
#

ohhh yes

#

that would be cool

#

can do that

#

but question

#

what difference does it make?

#

wont it just be in an object either way?

dusky flicker
#

if you want to modify it, you dont need to write a raw object

#

with modify i mean, changing some data or adding a new one

fallow minnow
#

hmmm true

#

i already do that for my generator things

dusky flicker
#

im supposing that array would change during runtime

#

if it doesnt, i dont see a reason for so

fallow minnow
warm mason
fallow minnow
#

registering generators

warm mason
#

damn, that's very cool ui

fallow minnow
#

tyty

warm mason
#

I hope they will improve DDUI soon, cuz I don't want to struggle with JsonUI...

wary edge
#

Did they change onMineBlock that you need to set back to inventory to update durability?

dusky flicker
# fallow minnow

since everything follows the same pattern, i personally think that passing arguments and then creating the object inside the function would help

#

if ur not using ts, its pretty easy to write a typo

#

and get some weird error

#

i personally used to struggle with this kind of thing

fallow minnow
#

oh like

#

instead of typing out the "type" etc.. i just have arguments?

dusky flicker
#

then you simply document the function to tell what each parameter does

#

so you dont write something like
.register({displayname: "displayname", ...}) somewhere

fallow minnow
#

yeah

dusky flicker
#

for sure, this supossing your not using ts

#

but i didnt see anything related to ts on the codes you showed

fallow minnow
#

i do use ts

#

i havent used js in like 4 years ๐Ÿ˜ญ

dusky flicker
#

xd, mybad

fallow minnow
#

the errors are very nice

dusky flicker
#

so you can simply ignore this advice

fallow minnow
#

i mean its still nice

dusky flicker
#

and use an interface as argument

fallow minnow
#

yeah

untold magnet
#

can i detect the potion type in 2.5.0 api? and what should i use to do so?

buoyant canopy
buoyant canopy
untold magnet
#

like normal potions wont be detected, but the normal water bottle will be detected

zinc breach
#

can I use this for changing players skins?

#
function changeSkin(player1, player2) {
    const skin1 = player1.getComponent("minecraft:skin_id").value;
    player2.getComponent("minecraft:skin_id").valua = skin1
}
#

like would this work

sudden nest
#

what's this level_tick? is it related to scripting ?

open urchin
open urchin
sudden nest
#

not sure but i think yes, cause i am using my cache instead of getBlock, not sure if this is the culprit behind that spike

open urchin
#

caching Block instances shouldn't do anything like that, it'll just increase script memory usage

sudden nest
#

the scripting has an average of 10-40 though, so i am not sure where that came from.

sudden nest
wary edge
#

It's so stupid onHitBlock doesnt register if its mining.

zinc breach
dusky flicker
#

maybe it helps you to find out what caused the spike

snow knoll
fallow minnow
#

like not self hosting

lyric kestrel
lyric kestrel
#

๐Ÿ˜”

wary edge
#

Client scripting in 2026 isn't happening.

lyric kestrel
#

Worth a shot ๐Ÿ˜”

#

Are material instance definitions based on client?

#

If the definition of the texture is statically defined on the world, why couldn't the scripting method point to the texture definition defined by the world and not the client based texture?

#

Like gather it through the texture Atlas

sudden nest
fallow minnow
fallen cape
warped kelp
#

Hello! I come asking if there as an alternate for "on_hit" for weapons and tools that used to use the custom component that could be run via scripts with the function array

warped kelp
#

Hello! May I ask where I place the item custom component? Is it in components of the item or separate?

#

Thisi is so that a script to detect when an item is used or used to hit a thing gets read and runs a function!

warped kelp
thorn flicker
wary edge
round bone
#

I use the same approach across my projects also ๐Ÿ™‚

fallow minnow
round bone
fallow minnow
#

LETS GOOOO I GOT TEBEX LINKED TO MY SERVER AND DATABASE

mystic harness
#

EntityItemPickupBeforeEvent item property gives entity only? cus seems like typeId of it is just minecraft:item and not giving the actual typeId of an item

open urchin
mystic harness
#

oh okay thank you

night acorn
#

is there a way to set bools on MolangVariableMaps for particles? tryna set a var called variable.underwater to true, but im only seein methods for colours, floats and vecs.

#

or is it some falsey coalescing where 0 is false and 1 is true?

open urchin
#

booleans don't exist in molang
true is 1 and false is 0

cold grove
weary umbra
#

Is there away to get the mob thats inside a spawner?

thorn ocean
#

But no seriously, will Entity.target stay in beta forever???

wary edge
#

Who knows.

steep hamlet
#
LocationOutOfWorldBoundariesError: Trying to access location (-11.0, 173.0, -27.0) which is outside of the world boundaries.

said location is 10 blocks away from me. how is it outside the world boundaries?

steep hamlet
#

overworld and it was searching in nether ... xdd

#

thanks

dusky flicker
#

is there a way to modify the player fov?

#

without slowness i mean

distant tulip
dusky flicker
distant tulip
#

it have ease options

dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

nova flame
#
export default function JennyUI(player) {
    const inventory = player.getComponent("inventory").container;
    const coins = getScore(player, "Coins");

    const form = new ActionFormData();
    form.title("Extras");

    form.button("Blow");
    form.button("crack");
    form.button("dance");

    form.show(player).then(async (response) => {
        const i = response.selection;
        if (i === undefined) return;

        if (response.cancelationReason == "UserBusy") {
            return system.runTimeout(() => {
                JennyUI(player);
            }, 10);
        }

        if (i === 0) {
            blowJob(player);
        }
        if (i === 1) {
            crackJenny(player);
        }
        if (i === 2) {
            lapDance(player);
        }
    });
}```
can someone please tell me why its not waiting until the player is not busy to open the ui
slow walrus
#

bro

wary edge
#

BRO

#

๐Ÿ˜ญ

nova flame
#

im serious i need help

#

idk why it wont work๐Ÿ˜ญ

slow walrus
#

well, it's cause you're returning when there's no selection

#

and if the user is busy then there'll never be a selection

#

crazy work though

distant tulip
#

was going to say no one is helping you, but i guess someone need this add-on

dense wraith
stone bridge
#

hello there, how can i store some data in item?

#

i am trying to store it with .setDynamicProperty, but it seems like ynamic property disappears almost instantly

wary edge
#

Are you setting the item back to the container?

stone bridge
#

but now i will

#

thanks

earnest meadow
dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

wary edge
#

Stabilized in 26.10 if I recall.

dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

wary edge
#

I've been using it for loot protection. It's quite nice.

dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

wary edge
#

There are command macros but global.

dense wraith
#

One message removed from a suspended account.

wary edge
#

Per add-on though, I don't foresee it anytime soon, maybe late 2026 early 2027. Unlikely since it's keyboard only.

dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

stone bridge
# stone bridge thanks

isnt setdynamicproperty must do its work just well without any resavings? like if i call getdynamicproperty second time in tick, it gets it, but when i do it next time it gets empty again

wary edge
stone bridge
#

how to save it to the world easily

wary edge
stone bridge
#

thanks

stone bridge
#

works as intended

slim spear
#

so uh

#

when did they break getting the faceLocation form a block raycast?

#

i can get it, but it's false for some sides

#

like hitting the top of the block, y should be 1, but is 0

slow walrus
green bison
#

Hello all, is there any way to detect an item inside of a item frame?

open urchin
#

It's equivalent to the internal method used when using pick block

dusky flicker
#

is there a way to use async generators on runjob?

sharp elbow
#

I suppose not, but I wonder if a job (using a synchronous generator) could use asynchronous generators when combined with promises or yield*

lyric kestrel
#

I need a way to use a lot less block permutations for my add-on, as I'm already getting 93,220 ๐Ÿ˜…
I thought the way I was making my add-on was pretty scalable, but apparently it wasn't.
And now I'm unsure of how to lower it, and I've tried for a few weeks now to come up with an alternative

#

So wondering if anyone here has a clue

distant tulip
#

what are you currently doing

lyric kestrel
#

Problem is with so many texture changing, each texture change is a permutation/state

distant tulip
#

that doesn't answer my question

remote oyster
dusky flicker
#

like, if you got 6, and you know its 5x5, then 6 = (1,1)

distant tulip
#

the performance impact is not worth it, it might be best to use entity

buoyant canopy
#

is there any entity that getComponent("equippable") equippable work on other than the player?

warm mason
#

try to use player runtime id lol

buoyant canopy
#

not even armor stands?

snow knoll
buoyant canopy
#

they do have an inventory component???

#

i am looking at the entity file of armor stands, they don't

snow knoll
spice finch
#

Is there an easy way to make items on the ground unable to be picked up?

wary edge
spice finch
#

didn't know that was a thing. thx

#

another thing, is there anyway to spawn an item entity. it isn't one of the options in dimension.spawnEntity()

spice finch
#

ah, thanks

broken pawn
#
import {ItemStack} from '@minecraft/server'
dimension.spawnItem(new ItemStack('minecraft:egg',1),entity.location)
warm jungle
#

question, does scripting affects the ram? Like how much will the game consumes RAM, if you have alot of arrays and stuffs it's gonna slow down everything?

fallow minnow
#

even around 50mb -200mb of data is totally safe in my opinion

#

for my server at least

#

8gb of ram

#

but if its just for storing player data youre chilling lowkey

#

i save their data in cached memory and even if i hit 10kb per player which is around 10,000 characters its perfectly fine for 50 players

remote oyster
round bone
dusky flicker
#

at least the amount you can control

warm jungle
#

Thankk you for the answers ๐Ÿ™

subtle cove
#

i'd recommend using other data types too like Map & Set

dusky flicker
#

if the key is a string, probably its better to use a raw object

sharp elbow
#

In traditional settings, using Map vs object will typically depend on how many keys you expect to have.

#

IIRC objects lend better to smaller sets of keys. Maps lend better to larger sets of keys

hoary frigate
#

Does anyone have any idea how to remove the limited text in the new update
-# why would they do such thing ๐Ÿฅ€

#

-# context the command gets cut off cause of the text limit

lyric kestrel
#

Unless I was testing it wrongly, which I admit could be the case

dusky flicker
sharp elbow
#

Really depends. This is where we start running performance metrics

dusky flicker
#

all the knowledge you have about optimization can simply be thrown away depending on the runtime

sharp elbow
#

At least it is a known runtime; it's no guarantee, but in theory we can look up existing performance metrics of QuickJS and make some guesstimates on how it'd perform in Minecraft

dusky flicker
#

i mean

#

you got an Art that returns some ID idk, and use it as index inside an array

fallow minnow
#

what are some good ways to detect memory leaks?

lyric kestrel
last latch
lyric kestrel
fallow minnow
lyric kestrel
lyric kestrel
#

Fair

#

Would this not work the same?

fallow minnow
#

not really sure

#

i use my vps ip, local and others

#

opened ports

#

nothing worked

lyric kestrel
#

Did you put the configurations as shown "allow-outbound-script-debugging", "allow-inbound-script-debugging" into the server.properties file and set to true?

fallow minnow
#

yes

lyric kestrel
#

At what kind of world tick in Milliseconds is considered slow/bad?

subtle cove
fallow minnow
lyric kestrel
#

Idk how to check tps ๐Ÿ˜…

#

I just know how to check like server in MS

#

Through the Bedrock debugger

last latch
dusky flicker
#

the garbage collector does so for you

#

the unique thing i'd say is to dont save too much data that cannot be deallocated due to something pointing to it

fallow minnow
#

htop and some RSS readers and just logging everything and comparing

dusky flicker
#

but you could try using it

#

sorry, not debugger

#

profiller

fallow minnow
#

i cant get it to link ๐Ÿ˜ญ

#

oh yeah

#

no i cant get it to link

#

and i mean it seems to be fine

#

the mem keeps slowly rising but im not too sure if its from a memory leak

#

i started at like 2.33gb

#

but then the RSS for the bedrock server isnt really rising

#

it fluctuates a lot

lyric kestrel
#

Holy

fallow minnow
#

?

#

is that bad

dusky flicker
fallow minnow
#

thats not just the bds btw

dusky flicker
#

htop sees everything

fallow minnow
#

thats everything

#

bot, bedrock server, website, sql database

dusky flicker
#

and minecraft by itself might have alot of things cached

#

that would make it harder for you to figure out if its your addon or not

fallow minnow
#

true

#

and it just goes up and down up an down

lyric kestrel
#

Like are you doing anything?

fallow minnow
#

but umm i started at 803

#

nope just sitting in the world

lyric kestrel
#

Could be surrounding chunks at the edge loading?

#

But I mean, 2GB only isn't really bad at all

fallow minnow
#

i think what ill do is

lyric kestrel
#

Bedrock Debugger tells me I use 3GB on a superflat world

fallow minnow
#

so i publicly exposed my bridge for discord to minecraft and my database

#

im just going to host the server on another vps

#

and talk to this other one

#

and then just closely monitor the one with the bds on it

#

but i honestly think its just caching minecraft stuff

#

chunks and what not

#

went from 925 to 913

lyric kestrel
#

Could be

fallow minnow
#

2.44 gb to 2.41

#

back up to 2.44

lyric kestrel
#

Ye, that's not bad at all

#

That's just usual

fallow minnow
#

i dont mind the steady growth as ill reset the server every few hours either way

lyric kestrel
#

Just leave it up for a few hours and see how high it goes

fallow minnow
#

but as long as its not like consistantly just going up

dusky flicker
#

seriously, its not an addon that will make the memory blow

lyric kestrel
fallow minnow
lyric kestrel
#

So like unless it's Discord levels of Memory Leakage; it's not really a worry

fallow minnow
#

but yeah its def slowly going up

#

2.46 now

#

its like

#

an oscillation

lyric kestrel
#

Just keep it up for a few hours and see what it goes to

fallow minnow
#

yes

#

its been running for 1.5 hours now

#

if i dont exceed 3gb within the next 2 hours ill say its fine

#

not ideal

#

but still fine

dusky flicker
fallow minnow
#

im at 2.43 rn

#

2.43 gb

#

so if i get to 3 thats what like

#

570mb

#

yeah its like oscillating

#

just a trend upwards

lyric kestrel
#

@fallow minnow how is it now?

fallow minnow
#

interesting

#

oof now at 2.54

lyric kestrel
#

What does RSS mean?

#

But ye, it seems like there is a little bit of memory leakage within it

#

But it doesn't seem that bad

fallow minnow
near aspen
#

guys what is 26.0 script api versions

#

i cant find it

gaunt salmonBOT
slender aurora
#

Hello๐Ÿ‘‹
Just a short question: I have an item that I want to use with right click on an entity. If I wanted to use the playerInteractWithEntity, it would only count, if I interacted with the villager trading menu for example right?
So if I just wanted to use my item, I would have to use itemUse and than get the entity within the viewing direction of the play?

gaunt salmonBOT
ocean escarp
#

Is there any way to grab entity lore from a script to test against a different value?

ocean escarp
#

Aren't items on the ground entities tho?

ocean escarp
#

Can we access data with scripts?

winged drift
ocean escarp
#

[object undefined]

#

Or however it goes

#

The code is from my friend but they're too shy to post apparently

#
world.afterEvents.entitySpawn.subscribe((ev) => {
    world.sendMessage(toString(ev.entity.nameTag))
    world.sendMessage(toString(ev.entity.typeId))
    world.sendMessage(toString(ev.entity.getComponent("minecraft:item").itemStack.getLore())) 
    world.sendMessage("vulsmells") //very original ik
})
warm mason
#

and this should work

ocean escarp
dusky flicker
ocean escarp
dusky flicker
winged drift
#

maybe the item dosen't have a lore

#

that would throw errors

ocean escarp
#

I guess they didnt have an exception case

ocean escarp
remote oyster
#

You don't need to convert to a string when it already returns strings.

ocean escarp
#

Ah

remote oyster
#

Also, the method used to convert to a string was incorrect.

ocean escarp
#

Appreciate it but I'm already pondering alternative methods.
Can you distinguish between the item name and identifier in scripts easily?

remote oyster
#

Yes

ocean escarp
#

Because I was thinking of making a custom item that summons whatever it's named before deleting itself

remote oyster
#

Just have to read the string and verify if it's what you are seeking.

ocean escarp
#

test:mob_summoner

check name;
if not real return;
summon entity;
kill self;

remote oyster
#

That's the gist of it.

#

The logic and condition will be up to you.

woeful vine
#

Hey! Someone know why scripts don't work on realms and how can I make them work?

fair quarry
woeful vine
#

Idk what you need to knwo, but Ill provide it to you.

fair quarry
#

And console errors if possible

woeful vine
# fair quarry And console errors if possible

Nothing pops up, absolute void, nothing happens, not even the main file runs

{
  "format_version": 2,
  "metadata": {
    "authors": [
      "ItsBausan - Luminous Studios"
    ]
  },
  "header": {
    "name": "Planetoid scripts",
    "description": "1.0.1 - v91",
    "min_engine_version": [
      1,
      20,
      60
    ],
    "uuid": "ca937367-f360-4263-951b-b7a3cddc387b",
    "version": [
      1,
      0,
      0
    ]
  },
  "modules": [
    {
      "type": "data",
      "uuid": "f3ecc2e3-d66d-403d-8cc0-452d5f6fde73",
      "version": [
        1,
        0,
        0
      ]
    },
    {
      "type": "script",
      "language": "javascript",
      "entry": "scripts/main.js",
      "uuid": "61e237b7-56b6-4d76-b4e4-fb265710ca40",
      "version": [
        1,
        0,
        0
      ]
    }
  ],
    "dependencies": [
    {
      "module_name": "@minecraft/server",
      "version": "beta"
    },
    {
      "module_name": "@minecraft/server-ui",
      "version": "beta"
    }
  ]
}
woeful vine
#

Aight

#

Working now

#

WTF

#

Like, it just started working

#

I changed nothing sob_pray

fair quarry
#

lmao

#

next time check if the addon is added using /packstack server verbose exclude-vanilla

summer cloud
#

how do i create a itemStack of potion tipped arrows?

untold magnet
#

yao, my xCore addon (that has all of my addons functionality) has 49 dynamic properties and its total bytes count is 1455, is it fine? like when should i start caring about the dynamic properties impact on performance?

distant tulip
#

if you are not getting a warning you are fine

distant tulip
summer cloud
#

thats what i figured, its just a big pain to do it via commands

distant tulip
fallow minnow
#

@lyric kestrel alright so bad news @dusky flicker

#

dont mind the 0.01mb / hr, its actually aroumd 50-50mb/hr

#

although after around 8 hours the mem didnt reach 3gb its itll not good

#

def a leak

dusky flicker
#

but damn

#

it not that much

fallow minnow
#

yeah

#

its just weird though

dusky flicker
#

but it could be good enough for you to study

#

have you got any idea of where it could be?

fallow minnow
#

nope ๐Ÿ˜ญ

#

the biggest thing i store is player data

dusky flicker
#

i dont know exactly how to measure memory usage

fallow minnow
#

could it be like

#

tsc watch?

#

actually no

#

im going to try something

#

if its my scripts

dusky flicker
#

im checking it

fallow minnow
#

ill know if i reload and it drops

dusky flicker
#

ur running on windows?

fallow minnow
#

linux

dusky flicker
#

thank god

fallow minnow
#

im gonna reload and see

#

praying its just minecraft itself

dusky flicker
#

theres valgrind

#

im checking gpt

#

by the way

fallow minnow
#

okay rip it def is my code prob

#

after reload it dropped to freaking

#

1231291 node 644432 8.1

#

jeesususuususuu

#

2.16gb

#

okay im going to check through every single file

dusky flicker
#

try using valgrind for so

#

im checking it

#

seems to be interesting

fallow minnow
#
{"xuid":"2535438968243754","username":"uzis mine","coins":116912,"gems":103,"level":1,"last_online":1771893231264,"experience":0,"blocks_broken":545,"blocks_placed":524,"mobs_killed":1,"coin_multiplier":1.3,"owned_cosmetics":[12,20,21,22,23,24],"selected_cosmetics":{"hat":0,"cape":0,"rank":21},"rank_text":"Elite","entitlements":{"elite":true},"daily_quests":{"t":2,"v":2,"seed":436268936,"slots":[{"c":0,"p":0},{"c":0,"p":0},{"c":0,"p":0},{"c":0,"p":0},{"c":0,"p":0},{"c":0,"p":2},{"c":0,"p":0},{"c":0,"p":0},{"c":1,"p":43}],"dayKey":"2026-02-23"}}``` this is the most amount of data i store
#

which never gets set to the cache again

dusky flicker
#

as json?

fallow minnow
#

yes just for testing

#

well so

#

its stored as sql columns

#

and i just convert to json structure and cache it

dusky flicker
#

oh, so its not bad as i thought

#

i thought you were using json as db

fallow minnow
#

yeah noo

#

๐Ÿ˜ญ

#

but i 100% have a leak

#

which wil be so annoying to find

dusky flicker
#

cant you show the code?

#

so i can check it

#

and try to help to find out

fallow minnow
#

wellll

#

its a lot

dusky flicker
#

as long as its understandable

#

its not a problem

fallow minnow
dusky flicker
#

what do you suppose its?

fallow minnow
#
const from = { x: -370, y: 82, z: -38 };
const to = { x: -364, y: 75, z: -37 };

const volMin = {
    x: Math.min(from.x, to.x),
    y: Math.min(from.y, to.y),
    z: Math.min(from.z, to.z),
};
const volMax = {
    x: Math.max(from.x, to.x),
    y: Math.max(from.y, to.y),
    z: Math.max(from.z, to.z),
};

function isInsideBlock(pos: Vector3) {
    return new BlockVolume(volMin, volMax).isInside(pos);
}

const island = new IslandManager();
const handledPlayers = new Set<string>();
const lastInside = new Map<string, boolean>();
system.runInterval(() => {
    for (const player of world.getPlayers()) {
        const xuid = player.xuid;
        const insideNow = isInsideBlock(player.location);
        const insideBefore = lastInside.get(xuid) ?? false;
        lastInside.set(xuid, insideNow);
        if (handledPlayers.has(xuid)) continue;
        if (!insideBefore && insideNow) {
            handledPlayers.add(xuid);
            (async () => {
                try {
                    const hasIsland = await island.has(xuid);
                    if (!hasIsland) {
                        await islandSelection(player);
                        return;
                    }
                    island.teleport(player);
                } finally {
                    handledPlayers.delete(xuid);
                }
            })();
        }
    }
}, 20);```
#

oka nvm not that

dusky flicker
slow walrus
fallow minnow
#

so its just a whole bunch of random maps and sets and etc

remote oyster
#

Memory leaks are fun ๐Ÿ˜œ

fallow minnow
#

genuinely have no idea what its from so

#

but im switching over ALL of my registries and everthing to my cache class

#

then we will see

remote oyster
#

That code you shared has a memory leak with lastInside. That map gradually accumulates data and when players leave or disconnect that data isn't being cleaned up.

fallow minnow
#

yeah i changed it to just automatically delete the players lastInside after it completes

remote oyster
#

I'm sure you got a lot of code to look at but anything storing data in memory needs to be verified if that memory is being handled in cases where the data is no longer relevant. Such in cases where a player leaves or disconnects.

#

Memory should be temporary storage, not permanent.

fallow minnow
#

the only memory i store for the player is their island data and player data

#

which are both deleted after they leave

#

but i also cache things like

#

cosmetic entries from my database, registered enchants, registered generators, quest templates, command registry, reward templates

fallow minnow
#

okay i fixed everything to use the cache thing i have and hopefully fixed the memory leaks

#

looking good so far

sly valve
#

yo

#

Is there a list of every API Error? (like ReferenceError: Native function [Class::method] does not have required privileges)

severe forge
#

Is there a way to get the player's skin by scripting?

cold grove
#

for example before events

sly valve
wary edge
sly valve
#

But I doubt I might find anything

sly valve
wary edge
sly valve
wary edge
#

Correct.

sly valve
# wary edge Correct.

By any chance, do you know the thrown Error instance? I cannot find anything nor test

wary edge
#

Not off the top of my head no.

sly valve
#

Alright, still thanks RosThumbUp

fallow minnow
#

@dusky flicker looking good?

#

its stable hovering for the past 10-20 minutes

#

thank the lord

fallow minnow
#

nvm it just keeps steadily growing

#

this is so weird

light nest
#

can script detect block's collision? example if a block has a collision size not more than [8, ~, 8] then it will return true

cinder shadow
#

we can't cancel the message for when a player joins the world right?

fallow minnow
#

what i did is uh

#

i used json ui and just hid the "joined the game"

#

or world

#

BUT ive noticed something weird.

#

since ive "disabled" the join message, scripts still sometimes duplicate it..?

#

its very strange

cinder shadow
#

ah.. I'll see what happens when it's disabled in my game then

#

I finished implementing a friends list system and now it's kind of weird since there are double messages

#

which just defeats the purpose of a friends list

#

beyond this

sly valve
#

Minecraft Bedrock API in a nutshell

fallow minnow
#

i can leave and join a whole bunch and itll just randomly duplicate when sending the message with player events after spawn

sly valve
#

Did Microsoft already switched from UWP to SDK? Last time I checked was a year ago

fallow minnow
#

GDK

#

yes

#

a lot buggier now tbh

sly valve
#

YaY

#

Aww

fallow minnow
#

but not too bad

#

i get some weird texture bugs

#

where textures just like

sly valve
#

Thanks Microsoft for nothing but bugs

fallow minnow
#

replace eachother or just disregard what ive changed in my rps

sly valve
#

I hope the CEO of Microsoft gets replaced

fallow minnow
#

๐Ÿ˜ญ

sly valve
fallow minnow
#

also i pinpointed my MEMORY LEAK / ALLOCATION CHURN thing ๐Ÿ˜ˆ ๐Ÿ˜ˆ ๐Ÿ˜ˆ

sly valve
fallow minnow
#

it was my wind thing which checks the surrounding chunks around the player and randomizes wind speed with weird noise

#

and my sidebar??

#

i guess

#

i was being stupid and umm

#

i was spam showing the sidebar every tick WHILE getting the players ping every single tick

sly valve
#

WHAT

fallow minnow
#

which returns a promise

sly valve
#

AHHHHHHH

#

UNOPTIMIZED CODE

fallow minnow
#

i didnt know it was that bad ๐Ÿ˜ญ

#

im using endstone so

#

i dont normally have access to ping

#

but i was also calculating the tps and displaying it every tick

sly valve
#

I feel bad for your IDE

#

oh and your kernel

#

and your cpu

#

and your hdd

#

and ram

fallow minnow
#

my cpu is fine tbh

#

im honestly thinking about just hosting everything on this vps

#

its only $4.90

#

4vCores, 8gb ram, 75gb ssd

sly valve
#

yeah, let your pc rest

#

anyways gtg, I spent the last 10 hours with no sleep on something stupid

fallow minnow
#

same

#

like 15 hours just graphing memory usage

#

๐Ÿ’€

sly valve
#

-# i wrote my own server module API

#

hmh, progamming

#

needs to get longer tbh

#

gnn

dusky flicker
fallow minnow
#

๐Ÿ˜ญ

#

i tested the same way by just sitting in the world for an hour and i disabled my wind interval and sidebar interval

#

only ~50mb /hr

#

which seems normal

dusky flicker
#

no way how was a wind system having leak

fallow minnow
#

IDK ๐Ÿ˜ญ

#

it was like

dusky flicker
#

xd

summer cloud
#

is there a way to put dynamic values into command selectors?

fallow minnow
#

i was at like

#

like 150-200mb /hr

#

now its at 55

#

it does go up but not enough for me to optimize more

#

and its most likely just minecraft doing whatever it does

dusky flicker
#

weird how minecraft can't find the memory leak by itself

#

i think they should add a flag or something to stop the addon or something

#

when the memory increases

fallow minnow
#

or if they could just document how to connect the uhh

#

whatever its called

dusky flicker
#

profiller?

fallow minnow
#

yeah

#

i cant seem to link it with my vps

dusky flicker
#

man as far as i used it

fallow minnow
#

i did port 19144 vps ip

#

i opened up the port just to test

#

wouldnt work

#

nothing

dusky flicker
#

first i start it on the vscode with listen if im not mistaken

fallow minnow
#

yes

dusky flicker
#

and on minecraft connect it to the same port

fallow minnow
#

yeah but it just doesnt work ๐Ÿ˜ญ

dusky flicker
#

but i use the terminal

fallow minnow
#

oh i used that weird json thing

dusky flicker
#

so minecraft is forcing me to use vscode

#

like seriously

#

why mojang? ๐Ÿ˜ญ why?

sly valve
dusky flicker
#

but notepad++ isnt bad at all

dusky flicker
#

cant you open some issue or something like that

#

to ask mojang to detect when an addon uses too much memory?

sly valve
subtle cove
fallow minnow
#

is there a way to lessen the amount of entities that spawn from spawners?

#

like lessen the time

#

or something

dusky flicker
#

how do i get custom component information from an item?

#

i mean, not necessarily it being on a event executed from a custom component

wary edge
#

It should return a customComponentInstance and you can get tge parameters.

dusky flicker
sly valve
#

Gmorning

zinc breach
#

can you access dynamic properties in the world file

#

like see all the dynamic properties that were set on your world

sly valve
unreal saddle
#

Does anyone know why the script only works for me, but my friend gets this error every time he's hit by the entity I assigned?
[Scripting][error]-Error: Failed to resolve identity for 'GroberPC3843'. at <anonymous> (custom/menu_ent.js:139)

This is the code

const statueObj = world.scoreboard.getObjective("statue")
  ?? world.scoreboard.addObjective("statue", "statue");

world.afterEvents.entityHurt.subscribe(ev => {
  if (ev.hurtEntity instanceof Player && ev.damageSource?.damagingEntity?.typeId === "papu:medusa") {


    ev.hurtEntity.dimension.playSound("health_stone", ev.hurtEntity.location);

    let score = statueObj.getScore(ev.hurtEntity) ?? 0;
    score += 1;

    if (score > 20) score = 20;

    statueObj.setScore(ev.hurtEntity, score); //This is line 139
     ....
sly valve
#

Make sure his score is at least set to 0 before getting it

#

Maybe write a function to get a certain score and use try catch

winged drift
sly valve
sly valve
#

Should work

winged drift
sly valve
unreal saddle
winged drift
sly valve
winged drift
sly valve
#

When you create a scoreboard no one has a score until you add/set it to 0 or else

sly valve
#

But good to know, because I am writing my own Server module API (cant play Mcbe and got bored)

subtle cove
#

That errors comes from the entity having no ScoreboardIdentity like player.scoreboardIdentity is null where the entity currently has no score from any objective

#

Doing hsParticipant will try to look for the identity, which will make that error again.
But when entity is already a participant of other objective, hasParticipant will never throw

hybrid bobcat
#

Has anyone experienced an issue where reducing the damage below 1.0 in world.beforeEvents.entityHurt prevents the hurt entity from receiving invulnerability frames?

here's my code just in case someone want to test it

import { world } from "@minecraft/server"

world.beforeEvents.entityHurt.subscribe((event) => {
    event.damage *= 0.5
    world.sendMessage(`Damage: ${event.damage} || ${Math.random().toFixed(1)}`)
});
cinder chasm
#

Is it possible to make the costume block spawn XP by breaking it cuz I tried in the behavior pack and script and loot table ?

fallen cape
sly valve
#

Im not sure currently, better check the docs or try finding it when you have the npm installed

dusky flicker
#
"myaddon:modular_item": {
        "range": 80,
        "damage": 225,
        "knockback_strength": 12,
        "on_hold": {
          "movement_module": {
            "velocity": 3
          },
          "shooting_module": {
            "projectile_entity": "minecraft:arrow",
            "power": 3,
            "keep_shooting": true,
            "shot_interval": 2
          }
        },
        "on_desselect": {
          "shooting_module": {
            "stop_shooting": true
          }
        },
        "on_sneak": {
          "dash_module": {
            "velocity": 2,
            "rotation": 1.57,
            "y_power": 1
          }
        }
      }```

Is this organized enough?
#

just setup a 'module' inside the component, and thats it, you ready to go

dusky flicker
#

no way '-'

#

why in hell would they limit the depth of files?

wary edge
dusky flicker
dusky flicker
#

damn i never thought id need to use dod knowledge in json

sly valve
#

Hello!

#

When does startup gets called and when worldLoad
is there a static sequence?

wary edge
sly valve
ocean escarp
#

We are using Includes because getLore by itself wasn't working

somber rapids
#

with includes it doesnt check if it only has those, but if it has those alongside anything else. Right now the problem is i dont know how the getLore returns its value, and the variants i tried didnt work

winged drift
somber rapids
#

ngl the values being returned are js annoying, i'm tryna get a different thing working but it aint, even though it allows me to use the value as a string later in my code with no issue
world.sendMessage(ev.entity.getComponent("minecraft:item").itemStack.nameTag)

somber rapids
cinder shadow
ocean escarp
cinder shadow
#

If you want an exact match, just do loreString === "Expected String"

ocean escarp
#

Since no other would have the same lore

marble sigil
#

Is it possible to make a particle size bigger or smaller by spawning via Scripts?

#

Performance matters btw.

thorn flicker
thorn flicker
#

yes

marble sigil
#

like if I .setFloat("r",5), then v.r in the particle json is 5?

thorn flicker
#

mhm

marble sigil
#

Okay ty I figured out ๐Ÿ˜Œ

thorn flicker
marble sigil
#

good to know

untold magnet
untold magnet
#

@distant tulip this is what i meant by 'detecting when the player jumps' bao_act_upvote

distant tulip
#

there is an evemt for that if it is not what you are using

untold magnet
distant tulip
#

PlayerButtonInputAfterEvent

untold magnet
#

it will only detect when the button is pressed or hold,

distant tulip
#

you are overcomplicating things

untold magnet
warm mason
untold magnet
distant tulip
untold magnet
# warm mason just add a ``player.isJumping`` condition
import {world, system} from '@minecraft/server';

export const ePlayers = new Set();

world.afterEvents.playerJoin.subscribe(({playerId}) => {ePlayers.add(playerId)});
world.afterEvents.playerLeave.subscribe(({playerId}) => {ePlayers.delete(playerId)});

system.runInterval(() => {
    for (const ID of ePlayers) {const player = world.getEntity(ID);
        if (!player?.isValid) return;
        if (player?.isJumping) console.warn('jump')
    };
});;```
untold magnet
#

-# unless if im doing it wrong and i have no clue how it should work,

distant tulip
#

bro,,,
runInterval is not the way

warm mason
untold magnet
distant tulip
untold magnet
#

just.. show me an example of that work, or just send me the script so i can test it out

warm mason
# untold magnet just.. show me an example of that work, or just send me the script so i can test...
/** @type {Record<String, import('@minecraft/server').Player>} */
const PlayersMap = {};

/** @param {WeakSet<import('@minecraft/server').Player>} */
const PlayerHasJumped = new WeakSet();

world.afterEvents.playerSpawn.subscribe(data => {
    if (data.initialSpawn) PlayersMap[data.player.id] = data.player;
});

world.afterEvents.playerLeave.subscribe(data => delete PlayersMap[data.playerId]);

system.runInterval(() => {
    for (const player of Object.values(PlayersMap)) {
        if (!player.isValid) continue;

        const isJumping = player.isJumping; const hasJumped = PlayerHasJumped.has(player);

        if (!isJumping && hasJumped) PlayerHasJumped.delete(player);
        else if (isJumping && !hasJumped) {
            PlayerHasJumped.add(player);
            console.warn('jump');
        }
    }
});
``` not tested
warm mason
warm mason
untold magnet
#

works perfectly fine when u press the jump button,

distant tulip
untold magnet
#

lemme test my one with auto jump

warm mason
warm mason
# untold magnet doesnt work properly,
/** @type {Record<String, import('@minecraft/server').Player>} */
const PlayersMap = {};

/** @param {WeakSet<import('@minecraft/server').Player>} */
const PlayerHasJumped = new WeakSet();

world.afterEvents.playerSpawn.subscribe(data => {
    if (data.initialSpawn) PlayersMap[data.player.id] = data.player;
});

world.afterEvents.playerLeave.subscribe(data => delete PlayersMap[data.playerId]);

system.runInterval(() => {
    for (const player of Object.values(PlayersMap)) {
        if (!player.isValid) continue;

        const isJumping = player.isJumping; const hasJumped = PlayerHasJumped.has(player);

        if (hasJumped && (!isJumping || player.isOnGround)) PlayerHasJumped.delete(player);
        else if (isJumping && !hasJumped) {
            PlayerHasJumped.add(player);
            console.warn('jump');
        }
    }
});
``` try this
untold magnet
#

hmm

warm mason
warm mason
untold magnet
# warm mason ?

spam the event while standing below a slab and holding the jump button

untold magnet
untold magnet
# warm mason Well I tried...
import {world, system} from '@minecraft/server';

const jumpCache = new Map();
export const ePlayers = new Set();

world.afterEvents.playerJoin.subscribe(({playerId}) => {ePlayers.add(playerId)});
world.afterEvents.playerLeave.subscribe(({playerId}) => {ePlayers.delete(playerId); jumpCache.delete(playerId)});

system.runInterval(() => {
    for (const ID of ePlayers) {const player = world.getEntity(ID);
        if (!player?.isValid) return;
        const yVelocity = player?.getVelocity().y;
        const hasJumped = jumpCache.get(player?.id) ?? 0;

        if (player?.isOnGround) jumpCache.set(player?.id, 0);
        if (!player?.isOnGround && yVelocity > 0 && hasJumped === 0) {jumpCache.set(player?.id, 1); console.warn('jump')};
    };
});;```final results
#

now falling from blocks doesnt count as jumps,

untold magnet
dusky flicker
#

you could simply check when the player presses to jump

#

and check if hes on the ground

untold magnet
#

-# auto jump...

dusky flicker
#

-# why writing like this?...

untold magnet
dusky flicker
untold magnet
warm mason
#

๐Ÿ˜ญ

untold magnet
#

i haven't tested those things yet

dusky flicker
untold magnet
dusky flicker
#

and then improve the way the stamina system works

somber rapids
#

if setlore() requires an array, how does it return the value in getlore()?

warm mason
somber rapids
#

so far i tried to and either i did it wrong, or its not reading as an array

fiery solar
ocean escarp
fiery solar
# ocean escarp If standard Null / undefined checks aren't working. What could be a possible cau...

Do you mean you're trying to check if an item has no lore?

How are you checking? getLore returns an array, so if an item has no lore it will give you []

But you can't check if the lore === [] because that's always going to return false. Equality checks on arrays in JavaScript don't check that the value of the arrays are the same, they just check if the two sides of the equals sign reference the same array.

That's why [] === [] is always false.

ocean escarp
#

Im ngl the code is so ugly rn and I would fix it myself if I had the skill but it's a joint project and I'm more just the gameplay designer guy

fiery solar
#

Can you explain more about what you're trying to do? There's almost definitely a better way to do it than using lore

ocean escarp
#

Since we can't run mob summons in loot tables we are trying to make an item that does that
If it exists in the world it'll check its name and use this formatting to summon entities

<typeId / name> <amount> <nameTag>

somber rapids
#

i made that code

#
world.afterEvents.entitySpawn.subscribe((ev) => {
    if (ev.entity.typeId == "minecraft:item") {
        const name = ev.entity.getComponent("minecraft:item").itemStack.nameTag ?? "null"
        const lore = ev.entity.getComponent("minecraft:item").itemStack.getLore()
        const type = ev.entity.getComponent("minecraft:item").itemStack.typeId
        const spawner = name.split(" ")
        if (type == "cnr:omnispawner" && name != "null") {
            if (name.includes(" ") && spawner.length > 1 && isNaN(spawner[1]) != true) {
                const count = Math.min(Number(spawner[1]),64)
                if (spawner.length == 3) {
                    for (let i = 1; i <= count; i++) {
                        try {ev.entity.runCommand("Summon " + spawner[0] + " " + spawner[2])} 
                        catch {ev.entity.kill()}
                    }
                    ev.entity.kill()
                } else{
                    for (let i = 1; i <= count; i++) {
                        try {ev.entity.runCommand("Summon " + spawner[0])} 
                        catch {ev.entity.kill()}
                    }
                    try {ev.entity.kill()} catch{}
                }
            } else {
                try {ev.entity.runCommand("Summon " + spawner[0])}
                catch {}
                ev.entity.kill()
            }
        }
        else {
            if (type == "cnr:omnispawner") {
                ev.entity.kill()
            }
        }
    }
})```
ocean escarp
ocean escarp
#

now it's just code compaction, we figured it out while looking for the solution (crazy I know)

warm mason
small depot
#

and start testing your files one by one

#

unless you have any clue of what is causing the memory leak

distant tulip
#

there is memory usage there iirc

small depot
#

it could be variables, maps, jobs, or promises accumulating

small depot
warm mason
# ocean escarp Cause we had trouble testing names before, it's fixed
const EntitySpawnerItemId = "item_type_id";

world.afterEvents.entitySpawn.subscribe(data => {
    const entity = data.entity;
    if (entity.typeId != 'minecraft:item' || !entity.isValid) return;

    const item = entity.getComponent('item')?.itemStack;
    if (item.typeId != EntitySpawnerItemId) return;

    const dimension = entity.dimension;
    const location = entity.location;
    entity.remove();

    const spawnerData = item.nameTag.split(' ');
    const spawnAmount = Number(spawnerData[1]) * item.amount;
    const spawnTypeId = spawnerData[0];
    const spawnNameTag = spawnerData[2];

    for (let i = 0; i < spawnAmount; i++) {
        const spawnedEntity = dimension.spawnEntity(spawnTypeId, location);
        if (spawnNameTag) spawnedEntity.nameTag = spawnNameTag;
    }
});
``` try this
#

and change EntitySpawnerItemId to your item type id

somber rapids
#

specifically instances such as this, where some arguments are correct, and others arent
my own code ensured that as long as the first argument was correct, the others either would be ignored, or would adapt (so if it was the below image, it would spawn a skeleton with name "aa" rather than just nothing at all)

#

i'm pretty impressed with the code you gave, so while i could modify it to add these exceptions, im sure that my changes would probably make it look just as bad as before

#

out of curiosity, why is there a semicolon on every line?

open urchin
#

Semicolons separate statements
Line breaks can also implicitly separate statements in JavaScript so having them at the end of lines is optional but I prefer having them personally since it makes copy/pasting easier

lyric kestrel
#

Ye, in other languages it'd be needed, but JS has something called "Automatic Semi-colon Insertion"

#

So when the compiler is compiling, it automatically inserts ; after statements

sharp elbow
#

Automatic semi-colons are a nice convenience but explicit is always better IMO. There are a couple of cases where newlines don't delimit meaningful tokens like you would expect, and placing a semi-colon manually would change the behavior

somber rapids
somber rapids
sharp elbow
#

In a case like this, ASI cannot determine if the object literal (in parantheses) on line 3 should be its own statement, or if it is a function call on the variable a:

var a = "hi"
a
({foo: bar})
somber rapids
sharp elbow
#

It'd happen mostly where you're preparing code and might erase something, making a typo. I've needed to wrap object literals in parentheses for arrow functions and encountered something like that before

#

This may be a bit more demonstrable:

var a = {"hi"() {return 1}};
const b = a["hi"]
(a.hi() + 3).toFixed(2)
#

Should b be assigned to the method "hi" on a? Or should it be the result of calling "hi" on a?

#

Of course, erasing the parentheses on line 3 could solve this too.
Edited it to include an example where that is less trivial of a solution

dusky flicker
sharp elbow
#

If I replace the line breaks with spaces, it becomes more apparent:

var a = {"hi"() {return 1}}; const b = a["hi"] (a.hi() + 3).toFixed(2)
#

the JavaScript engine assumes a["hi"] (...) is an invocation, since it looks like an invocation

#

(It's probably a bit more technical than that if you want to get into operation sidedness, but that's the intuitive answer to me)

dusky flicker
#

holy hell

#

that makes sense

#

1 more reason i hate js

round bone
# dusky flicker 1 more reason i hate js

In my opinion, I don't really care about these features. Good JavaScript developer will switch to TypeScript and keep his code organized anyways, these code snippets are a good example why some people shoudn't even touch this language

#

It's not the best for every single thing on this planet, but it gets job done and even the biggest companies like X (Twitter), Adidas, Uber, LinkedIn use it on backend

dusky flicker
#

and to learn as well

#

so you wont pay as much as you'd for C devs for example

#

i mean, here on brazil i've seen a job vacancy for rust, about 20k BRL, in dolars right now it might be around 4K, but for us that amount is insane, since the minimum wage on brazil is around 1500 brl

#

in general for js here i see at most, 7k brl

round bone
#

Web development in general is mostly less worth than Rust and some other niche languages like Elixir

summer cloud
#

Whats the default particle minecraft uses for death, im replacing it

untold magnet
#

is there other ways that makes u no longer onGround?

#

elytra doesnt count bec u have to jump to activate it,

dusky flicker
#

if so

#

you can do a system that you check the velocity of the player

#

and check the position near him

untold magnet
#

getting a vertical knockback will count, like from explosions will count as a jump

dusky flicker
#

i mean

#

if the player did get y velocity, very close to a block

#

a single block i mean

#

you emit the event

#

and the rest keep as input