#Script API General

1 messages · Page 2 of 1

amber granite
#

The length isn't a big deal

distant gulch
#

hmm okay

amber granite
#

for ( let i = 0 , i< array.length ; i++ )

distant gulch
#

so for veryyy big arrays

const arrayLength = myArray.length;

for (let index = 0; index < arrayLength; index++) {
  // ....
};

??

amber granite
#

Yep

#

Use forEcah for small arrays , because it s faster to write

#

And tge impact is very small

distant gulch
#

that's not a good argument

#

but when the perfomance doest decreases i would use more array methods

amber granite
#

If you're iterating over an array with 100,000 items, a traditional for loop is likely the fastest option. Here’s a quick comparison:

  • For Loop: Most efficient in terms of performance.

    for (let i = 0; i < array.length; i++) {
        // process array[i]
    }
    
  • forEach: More readable, but generally slower due to function overhead.

    array.forEach(item => {
        // process item
    });
    
  • for...in: Not recommended for arrays; it iterates over all enumerable properties, which can lead to unexpected results.

For a large array, stick with the traditional for loop for better performance.

distant gulch
#
array.filter(...).map(...)

sometimes i use a loop instead of two array methods

amber granite
#

That s good too

#

Arrays methods are also slower

#

then the regular for loop

distant gulch
#
for (let i = 0; i < array.length; i++) {
    // process array[i]
};

isnt that very unperfomant?? every "run" it needs to get the array length again?

amber granite
#

U can put it in a variable

sharp elbow
#

Yea, you could store the array length into a variable and do the comparison against that

#

(can also do prefix increment in the loop update expression if you want to be fancy)

amber granite
#

U can also use
while loop

#

As u know the js isn't based on performance

#

If u want to control the performance use c++ or py or java

#

Because js is mainly used for site webs

#

So nobody really cares about the performance

sharp elbow
#

On the contrary, many of the web-focussed JavaScript engines work tirelessly to optimize how code is ran. And that is especially relevant to Minecraft too

distant gulch
#

hmm okay

sharp elbow
#

It may not be as fast as more traditionally machine-compiled code, but that does not mean people care not for how fast it can be

amber granite
#

If u want more performance for ur code

#

Clear the refrences for the variables or object that u won't use it anymore

#

To be collected by garbage collectors

#

If u have big Script and Database... Etc , use sorting algorithms

#

And those algorithms which will help the performance very well too

fickle pulsar
#

do yalls know how we can use other programming languages with js

amber granite
#

Or wait until Minecraft uses lua. instead of js

amber granite
#

"jsons" files

#

Frameworks

fickle pulsar
#

ok

amber granite
#

It needs well programming knowledge

fickle pulsar
#

i can work on it

amber granite
#

But the easiest way to do it

#

Use jsons and node js

fickle pulsar
#

c++ classes are way easier for me to make

amber granite
#

What type of linking do u need ?

fickle pulsar
#

nah

#

i was just curious

amber granite
#

Ok

#

If u mean transpilers

#

Like turning js into c++ code

#

Or vice versa

fickle pulsar
#

ooo

#

if transpliers exist

#

it is possible to make a replica of the minecraft enviroment in c++

valid ice
#

¯_(ツ)_/¯

dense skiff
#

... if you asking this because you don't want to learn js, learning js would probably be easier than doing that for you

sharp elbow
# amber granite If you're iterating over an array with 100,000 items, a traditional `for` loop i...

These were the times I got from iterating over an array of 1,000,000. I tested each result ten times and averaged the result
Array.prototype.map: 262.5 ms
do..while loop: 224.1 ms
C-style for loop: 228.5 ms
Array.prototype.forEach: 217.9 ms
while loop: 206.6 ms
for..of loop: 205.2 ms

As anticipated, Array.prototype.map is not all that good, but someone should not be using that to iterate over an array anyway (unless they needed the results). for..of and while were better than the others, but only negligibly

#

In each loop, I was doing an assignment of i = i * i + Math.sqrt(i); (with i being the value at the index of the array) (I stole the idea from some random post I saw online)

ancient sierra
#

Hello! What's the latest version of @minecraft/server?

Thanks! bao_doggo_happy

fast lark
#

I found out what causes it

#
world.beforeEvents.itemUse.subscribe(data => {
    let player = data.source
    if (data.itemStack.typeId == "minecraft:recovery_compass") system.run(() => main(player))
sharp elbow
ancient sierra
#

I see, thanks again!

amber granite
sharp elbow
#

They may. I tested this on Windows 11, v1.21.1.

prisma shard
#

ello

#

hows going on

fast lark
prisma shard
#

help w/ what

fast lark
amber granite
#

The error

prisma shard
#

show errro

#

error*

fast lark
#

wait

amber granite
#

Did u import

#

World ?

fast lark
#

yes

#

import { world, system, ItemStack } from "@minecraft/server"

amber granite
#

What the error that got logged

fast lark
amber granite
#

In console

#

It s syntax error

#

If u got SyntaxError that means u didn't close paranthes

#

Or curly braces

fast lark
prisma shard
#

?

#

Wait i will fix

amber granite
prisma shard
#

I know

fast lark
#

.-.

prisma shard
# fast lark
world.beforeEvents.itemUse.subscribe(data => {
    let player = data.source
    if (data.itemStack.typeId === "minecraft:recovery_compass") {
system.run(() => {
 main(player)
})
}
})
amber granite
#

Do u use IDE ?

fast lark
amber granite
#

When someone asks for help here everybody rush to help XD

prisma shard
#

xd

amber granite
#

That s funny

shy leaf
#

reminds me of someone

prisma shard
shy leaf
#

a guy

prisma shard
#

a guy, but who

fast lark
#

a guy

shy leaf
#

who made their code with like

prisma shard
#

with like?

#

with what?

shy leaf
#

fuckleton of if else

prisma shard
#

☠️

#

bruh

shy leaf
#
  • making every single model bones
#

animated

#

with code

prisma shard
#

☠️

#

I am choking

solar dagger
#

Has anyone made a hunger meter for items?

odd sky
#

I don't suppose someone knows why this is failing

cinder shadow
#

where's the code?

#

Is it in a loop that adds several enchantments at once?

odd sky
#
enchantable.addEnchantment({ type: EnchantmentTypes.get('piercing'), level: 1 })
cinder shadow
#

The enchantment errors outputs are terrible

#

you're trying to add an enchantment to something that can't accept the enchantment

#

It already has another enchantment in the same group that 'piercing' is in

#

I think that was the issue, at least

odd sky
#

That's odd considering I'm checking if it can be added enchantable.canAddEnchantment()

cinder shadow
#

I think that might be what's throwing the error tbh

odd sky
#

I do have multishot also being added, forgot those were incompatible. Going to remove that and check

#

Yeah that solved it

#

Thanks

cinder shadow
#

I think .canAddEnchantment also works by adding it to the itemStack to see if it's valid, then removing it. Which would just error it out.

neat hound
#

Can also be if it has that enchantment and you add same, maybe it would take the level higher than can be. Can that checking thing check for that, do you give it the proposed enchantment with level?

odd sky
#

And I don't have piercing being added anywhere else

thorn ocean
#

There is no way to have constantly updating server forms, correct?

somber onyx
#
    export function getInv(player) {
        let inv = []
        for (let i = 0; i < 36; i++) {
            let container = player.getComponent("minecraft:inventory").container
            inv.push(container.getItem(i) ?? { typeId: "§cAir", amount: 0})
        }
        let form = new ActionFormData()
        .title("§9Mon Inv")
        .body("")
        inv.forEach(it => {
            form.button(`§u${it.typeId.replace('minecraft:',"").replace("_"," ")}`)
        })
        form.show(player)
    }

I was given this function but I do not know how to get the quantity of an item present in a slot despite the fact that I understand the function

#

someone would help me

odd sky
fading sand
#

how do i replace the item in my offhand with an item that canot be moved and is slot locked?

#

i forgot

thorn ocean
odd sky
#

Yes

fading sand
#
if (offhandItemStack.typeId.endsWith('_off')) {
        let item = offhandItemStack.typeId.replace('_off', '')
        let itemLocking = item.lockMode = "locked";
        source.getComponent('equippable').setEquipment('Offhand', itemName)
    }

would this replace the item named _off at the end with an item that is locked and is not th off named item?

amber granite
#

What ?

solar dagger
#
world.afterEvents.playerInteractWithEntity.subscribe(({ player, target }) => {
  const ridingComp = player.getComponent('minecraft:riding');
  if (ridingComp && target.typeId === 'fs:mammoth') {
    const mount = ridingComp.entityRidingOn.typeId;
    if (mount === target.typeId) {
      if (target.getComponent('minecraft:is_saddled')) {
        itemTransfer(player, target);
      } else {
        console.error('Target does not have a saddle');
      }
    } else {
      console.error('Target entity does not match the entity player is riding');
    }
  } else {
    console.error('Player is not riding an entity');
  }
});```
```txt
[Scripting][error]-Plugin [Flame and Steel Behaviors - 0.0.1] - [index.js] ran with error: [TypeError: cannot read property 'subscribe' of undefined    at <anonymous> (index.js:1184)
]```I seem to get this error...yes im using beta api v1.12.0

Could it be because the itemStack is undefined?
fading sand
# amber granite What ?
world.afterEvents.itemStartUse.subscribe(async event => {

    const { itemStack, source } = event

    if (!itemStack.typeId.startsWith('id:nvg_switcher')) return;
    let offhandItemStack = source.getComponent('equippable').getEquipment("Offhand")
    if (offhandItemStack.typeId.endsWith('_off')) {
        let item = offhandItemStack.typeId.replace('_off', '')
        let itemLocking = item.lockMode = "slot";
        source.getComponent('equippable').setEquipment('Offhand', itemName)
    }
    if (offhandItemStack.typeId.startsWith('nvg:') && !offhandItemStack.typeId.endsWith('_off')) {
        let item = "${offhandItemStack.typeId}_off"
        let itemLocking = item.lockMode = "none";
        source.getComponent('equippable').setEquipment('Offhand', itemName)
    }

})```
i basicaly want to do a item switcher
amber granite
#

Oh

amber granite
solar dagger
#

Im aware...

fading sand
amber granite
#

playerInteractWithEntity is the undefined

#

@solar dagger

amber granite
amber granite
#

I don't think so

#

Send me the manifest

#

And turn all experimentals

fading sand
amber granite
#

Test it then

#

But

#

Why did u use async @fading sand ?

fading sand
solar dagger
#

i fixed it nvm

amber granite
fading sand
#

why?

amber granite
#

It s not useful in this situation

fading sand
#

alr

#

ill remove than

amber granite
#

Because it will make

#

Ur code slower to excute

fading sand
#

ahh

#

atm i have one error by the way

#

let item = offhandItemStack.typeId.replace('_off', '')
let itemLocking = item.lockMode = "slot";

seems like item isnt an object or smth

#

@amber granite

#

maybe i need to set it first

valid ice
#

Just do item.lockMode

fading sand
#

or do newItemStack thingy

valid ice
#

Don’t set it to a variable

#

Can’t do the double equals like that there

fading sand
#

wait

#

but for that i would need to do an new item stack right?

valid ice
#

No

fading sand
#

oh ok, leme try than

valid ice
#

Oh I see what’s going on

#

You’re setting item variable to a string. A string does not have the lockMode property.

fading sand
#

oh, so what do i need to do in order to fix it?

valid ice
#

And itemName would be undefined, as it doesn’t exist in the code you sent

fading sand
#

oh

#

so what do i do now?

#

how can i make it not be a string but item

valid ice
#

Idk what you’re wanting to do

amber granite
fading sand
#

i wana do an item switcher

fading sand
amber granite
#

Create new stack

#

Then set it to players hand

fading sand
#

ahh, i knew it

amber granite
#

Because

#

They are different items

fading sand
#
let item = new ItemStack(offhandItemStack.typeId.replace('_off', ''), 1);
        item.lockMode = "slot";
        source.getComponent('equippable').setEquipment('Offhand', item)
amber granite
#

Yes

#

But what id item.lockMode ?

#

It s a string

#

Not an object

#

To make a proprety to it @fading sand

fading sand
#

?? I thought its an item stack now

amber granite
#

Yype id = string

#

They are the same thing

fading sand
#

yes, but item stack

distant gulch
#

Hello

fading sand
#

like it becomes an item stack

#

hi

amber granite
#

No it a type i

#

Id

#

That s not how js works

#

Xd

distant gulch
#

I want to make a Database with DynamicProperties, should i add a chache where the gotten data gets stored?

fading sand
#

so what do i do now?

#

wait

distant gulch
#

With new Map() or Array

fading sand
#

type id is without id right?

#

wait it isnt

#

im dumb rn

amber granite
#

I can't explain it frnow u don't have the required knowledge

distant gulch
#

I can help too!

#

And i need help too

amber granite
#

Wait...

fading sand
amber granite
#

I don't know if u can add costimzed proprety

#

On itemStack

valid ice
#

Item dynamic properties

amber granite
#

Yes that s better

fading sand
#

so what do i need to use than

#

to set an locked item with an certain name

amber granite
#

item.setDynamicProp

fading sand
#

and item is the string?

wary edge
#

New itemstack
Item.lockmode
Item. Blah blah
SetItem(item)

fading sand
#

but thats what i did

wary edge
distant gulch
fading sand
# wary edge Did it work?
let item = new ItemStack("${offhandItemStack.typeId}_off", 1);
        item.lockMode = "none";
        source.getComponent('equippable').setEquipment('Offhand', item)```
no
amber granite
#

I can't focus °-°

fading sand
#

wait

#

nvm

#

it did work

wary edge
distant gulch
#

Guys, when i want to make a cache with key and value, should i use the Map class

amber granite
#

Yes

#

Cache use map

distant gulch
#

okay good

amber granite
#

But

distant gulch
#

yes

fading sand
amber granite
distant gulch
#

A DataBase and i want to put the gotten datas in a cache

amber granite
#

Oh

#

What s the type of data ?

distant gulch
#

Key and Value ( value as string and normal )

amber granite
#

What about

#

Using a variable

amber granite
#

Or just shallow one

distant gulch
#

deep i would say

amber granite
#

U can stringify it

#

And put it as string in the world dynamic proprety

distant gulch
#

yes i want to do it like that

amber granite
#

And whenever u use parse the object

#

That will be better

distant gulch
#

i remeber now, i dont need encoded or decoded

amber granite
#

Yeah just use :
JSON.stringify

#

And put the loaded data in a variable

distant gulch
#

yes i know the method

amber granite
#

And that s it

#

And whenever u need the data parse it

distant gulch
#

but i just want to know, should i cache all the gotten data

amber granite
#

If the data is big!!

distant gulch
#

sometimes

amber granite
#

U know that cache is used for calculations after big process

#

That give u static return

#

Instead of recalculating it every time

#

So i don't think u need cache

#

Just use a string

#

And put it in a variable

distant gulch
#

i think you are missunderstanding me

amber granite
#

U are talking about loaded data right?

distant gulch
#

Yes, i mean when my databases like gets initialized, should i get from the start all the datas and store them, so i can get them directly from the storage or should i always get them by getDynamicProperty

amber granite
#

U means

#

Getting them from ram or rom

#

Because getDynamicPropreties uses rom and it s slower

distant gulch
#

Hmm okay

amber granite
#

And making it into a variable = cache it in ram

#

U need to Making it in a Variable if u want real fast result

distant gulch
#

what do you mean by variable, a map? like

const cache = new Map();
amber granite
#

I told u u need to stringify it

distant gulch
#

how should i be able to storage all the datas form the database in one variable

amber granite
#

'/"the stringified object"/"the next one"/'

distant gulch
#

yes but i dont save small datas

#

i want to save to like 500 objects

amber granite
#

The variable handles the big objects

#

How can i explain it to u

#

I m dumb in that

distant gulch
#

same

amber granite
#

But making the object as string is better for ur ram

#

Instead of using map

#

Because that will takes a lot of ram

distant gulch
#

I can't just save a huge stringified aobject with about 32K chars in one var and everytime i want to get a value i need to parse that

amber granite
#

And if u want to get an object u can just search in that string

hazy nebula
#

How to repair item with script 🤔

amber granite
#

And get the object and parse it

distant gulch
#

imagine parsing a 32k chars string

amber granite
amber granite
wary edge
amber granite
#

I mean search for ur object

hazy nebula
distant gulch
#

btw is DynamicProperty always better than scoreboard?

amber granite
#

And there is built in method in string

#

That let u get the object by name

#

And slice the part of that object

#

Then parse it

distant gulch
#

imagine the objects haves a key what haves the same name as the key i want to get

amber granite
#

I just used that method in my database

#

And it worked

distant gulch
#

isnt it a really slow mthod?

amber granite
#

But ram friendly

#

And not that slow

#

Because the variable itself is saved in ram

#

And the objects are small

distant gulch
#

when i need to get fast datas, and i hav elike 500 objects in there

distant gulch
amber granite
#

Same bro

distant gulch
#

hmmmm

amber granite
#

If u want map u can used it

#

Tho

#

Just put the object name

#

In the key

distant gulch
#

what exactly is ROM?

#

i only know RAM

amber granite
#

So

distant gulch
#

yes

amber granite
#

It s the hard drive

distant gulch
#

okay

amber granite
#

That s all XD

distant gulch
#

idk if my laptop evens haves a HD

amber granite
#

Exactly

distant gulch
#

i have an SSD storage

amber granite
#

The ram is faster then them

distant gulch
#

Okay, i dont think my Laptop haves a Hard Drive Disk because i use a SSD

amber granite
#

The hard drive is only to store things that the system won't use them

distant gulch
#

hmm okay

#

its build in the mainbaord?

#

mainboard*

amber granite
#

Yes and no

#

The rom ?

distant gulch
#

yes

amber granite
#

Yes and no

distant gulch
#

okay

fading sand
#

if i have an item that only has one tag, can i do this to get it?:
let tags = itemStack.getTags();?
or do i still need to get the full array

amber granite
#

The ssd are on the main board

#

And hdd are not

distant gulch
distant gulch
fading sand
amber granite
#

Just the Ram is faster

#

Then the fastest the rom

distant gulch
#

I have one SSD from Samsung build in

amber granite
#

That what u need to know

distant gulch
#

okay nice

amber granite
#

Ur images and files

#

Get saved in the rom

distant gulch
#

Are you german?

amber granite
#

No

fading sand
distant gulch
#

Yes

fading sand
#

alr thx

amber granite
distant gulch
#

RAM = Random Access Memory

#

ROM = ???

fading sand
#

cd rom

distant gulch
amber granite
#

Read only memory , or the dead memory

#

In some languages

amber granite
#

But not a big time

distant gulch
#

so the map Class saves the datas in the RAM?

amber granite
#

It s something linked to ur data size

amber granite
#

U can use it immediately

distant gulch
#

So that means, Objects are saved in the RAM and variables in the ROM =

amber granite
#

No

#

Variables are saved in ram too

#

Until ur serialize them

distant gulch
#

serialize?

amber granite
#

Yep

distant gulch
#

what does that mean exactly?

#

never heard of it

#

or my English limits found their end

amber granite
#

I must explain the computer science for u XD

distant gulch
amber granite
#

So u know the data in ur script

#

Get deleted

#

After u just exit the world

#

Because it s saved in ram

distant gulch
#

Yes

amber granite
#

But not in devices storage

distant gulch
#

okay

amber granite
#

So u need a process named serialisation

#

That write that data in ur ROM

distant gulch
#

okay but why

amber granite
#

What u mean by why ?

distant gulch
#

why should it write the data in ROM after deleting it in the RAM

amber granite
#

U doing that by making a db u silly XD

distant gulch
#

okay okay

amber granite
#

U kbow why dynamic propreties used for ?

#

Or no ?

distant gulch
#

not really

amber granite
#

So let s say

#

U want to save players items from the world start

distant gulch
#

Yes

amber granite
#

Until the time he exist the world forever

#

The script can't do that without access to Rom

#

The storage in ur device

distant gulch
amber granite
#

Ahhh

#

Let s say u want to save players death times

distant gulch
#

Sorrry either ist my english or your grammar

amber granite
#

Using script

distant gulch
#

Yes

amber granite
#

U can't do that with only script

#

Without saving the times that he died

#

Because u know the script is excuted in ram

distant gulch
#

yes, we need to likke storage his deaths somewhere

amber granite
#

That somewhere called ur ROM

distant gulch
amber granite
#

Or storage

amber granite
#

Because rom is so slow

#

And the device processor

#

Need something to save data in

#

His runTime data

#

Because that ram is more expensive then rom

distant gulch
#

yes, 64gb ddr4 ram costs about 100€

amber granite
#

As examples u find ram with 6 gb is expensive then rom with 200 gb

distant gulch
#

1TB ROM = less than 70€
64GB RAM = less than 120€

amber granite
#

That s how computer's work

amber granite
#

So u know the processure

#

I5 - intel

#

Or idk

distant gulch
#

thats why saving takes longer than the other shi*

amber granite
#

I7 - 10 th

distant gulch
#

i dont really know inter proccessors

#

i have an AMD ryzen

amber granite
#

Yes

#

The amd Ryzen u use

#

Called processor

distant gulch
#

Yes

amber granite
#

The processor needs a storage to save the data he proceeded in it

#

And here comes the ram

#

Without ram nothing in ur device will work

#

Because it s crazy fast

distant gulch
#

okay nice, btw lets continue it in dm, i need to go really fast rn

amber granite
#

Same as processor calculating speed

#

Ok

solar dagger
#

would i have to run an interval/job to check whether the player is riding a certain entity? or is there a event that i can use to help detect this?
@wary edge

distant gulch
#

Sorry, be right back

amber granite
#

Ok np

amber granite
#

I don't know

distant gulch
#

backkk

amber granite
#

Hey sorry

#

There some misunderstood in my messages

#

Rom is other type of data storage

#

U can't change it ever

distant gulch
#

hmm okay

amber granite
#

It used for system level

#

Things like bios

#

Etc...

distant gulch
#

okay, so read-only

amber granite
#

So i mean by rom = hdd or ssd

#

Because they are writable

distant gulch
#

okay

amber granite
#

Not like the rom which us soliderated into the mother borad itself

distant gulch
#

okay

amber granite
#

So , u need to get data from the hdd and ssd

#

And write in it

distant gulch
#

okay

amber granite
#

And ram is faster for that specific thing

distant gulch
#

and codes gets executen or saved in the ROM

#

RAM*

amber granite
#

No

#

In ssd

#

And hdd

distant gulch
#

okay so in ROM?

amber granite
distant gulch
#

read only thingy right

amber granite
#

I told u it misunderstood from me

amber granite
#

I mean by rom is hdd and ssd in the last speach

#

Because rom is something other..

distant gulch
#

so in HDD or SDD gets the code saved or executen?

amber granite
#

Yep get saved in

wary edge
#

What is this converstaion?

amber granite
#

About saving datas

distant gulch
#

main theme was a database

#

and the variable i have, lets call it rawCache

#

it gets saved in the HDD / SSD ?

amber granite
#

Yep it s saved in ram

distant gulch
#

okay ram

amber granite
#

The ram saves everything that cpu working with

distant gulch
#

Because its faster

amber granite
#

From getting data to setting data from and to it

amber granite
#

Because that it s expensive

distant gulch
#

yes
more efficiency > more expensive

amber granite
#

Yep

#

So .,

#

U code get excuted in ram

#

And all data associated with it

#

Got saved in ram

#

Until u exit the code

#

Then everything cleared

#

It s like humans short memory

distant gulch
#

Yes, but the code im having rn is either saved in the RAM when i didnt saved the code yet and when i save dit, its saved in the HDD / SSD?

amber granite
#

Yep

distant gulch
#

okay

amber granite
#

I mean only the essential data

#

Like objects

#

Etc...

#

I mean not the whole code

distant gulch
#

okay

amber granite
#

I mean only what u want to save and get it for later

distant gulch
#

okay

amber granite
#

So i told u to make a variable

#

And put strings of objects in it

#

Because it saved in ram

distant gulch
#

But a Map class is also saved their

amber granite
#

Yep

#

But hold more data

distant gulch
#

and it stakes longer thhe get single datas?

#

takes*

amber granite
#

No

#

I mean Map allocate as examples : 32 mb

#

As example

#

In RAM

#

But when u use a string instead

distant gulch
#

an empty one?

amber granite
#

No just an example

distant gulch
#

Okay

amber granite
#

It takes more lower then that

distant gulch
#

Okay because they are two arrays that are being saved or what?

amber granite
#

Two arrays ?

distant gulch
#

Ive seen the class Map works with two array

#

Key and Value array

amber granite
#

Oh

#

Yes

#

So u know js object

#

It doesn't saved types

distant gulch
#

What do you mean?

amber granite
#

I mean if u assigned proprety:

distant gulch
#

The JS object like [] or {}

amber granite
#
object = {}
object.true = 1
Is same as
object["true"] = 1 
amber granite
distant gulch
#

okay this object

amber granite
#

Yep

#

It has somethings called keys and values

distant gulch
#

yes, properties ad values

amber granite
#

So keys returned all to one type is string

#

U can't put boolean

#

Or number

#

Or null

#

Or idk

#

It all like
Let boolean = "true"

#

But not a real boolean type

distant gulch
#

okay so types wont be saved, they are ending up as a string?

amber granite
#

Yep

#

The "Keys"

#

Not the values

distant gulch
#

okay, plus point to arrays

#

yes iknow

amber granite
#

the arrays

#

Not a big deal

#

It just like

#

Putting two arrays in an object

#

Won't make a real thing

#

But see here

#

When using map

#
Let map = new Map()
distant gulch
#

yes

amber granite
#
map.set(true , 5);
map.set("true" , 5 )
distant gulch
#

will the first key be overwrited by the second one?

amber granite
#

No

#

They are separated

#

If u type

distant gulch
#

because of different types

amber granite
#

Yep

distant gulch
#

good

amber granite
#

That u can't do with regular object

#

There is another feature also

#

For maps

distant gulch
#

that's?

amber granite
#

U can put an object as key

distant gulch
#

wasnt it used for WeakMap??

amber granite
#

No

distant gulch
#

hmm okay

amber granite
#

Weak map are for something called refrence

distant gulch
#

okay okay

#

When i save something in map by using ann object as the key

#

i do need to have the same object as before to get it again?

amber granite
#

Sorry net get cutted off

#

For a min

distant gulch
#

No problem

amber granite
#

So u see

#

Lemme give u example

distant gulch
#

okay but how does the code knows, if object1 === object

amber granite
#

In Map ?

distant gulch
#

yes

amber granite
#

That s good question

distant gulch
#

i have read that you can't just compare objects like obj1 === obj2

amber granite
#

But i can respond it fn

distant gulch
#

no problem

amber granite
#
  • comparing objects is not like that
distant gulch
#

maybe by stringifying that object

amber granite
#

Ahhh

#

U know

#

Different objects

distant gulch
#

yes?

amber granite
#

Means they don't have the same propreties

distant gulch
#

yes, kinda

amber granite
#

If u put the same propreties u will get the same result

#

Even if u have individual ones

distant gulch
#

hmm

amber granite
#

Because in object situation

#

U need different object structure or names

#

Etc...

distant gulch
#

to identify them correctly?

amber granite
#

Yep

#

U can't as examples

#
Let object1 = { id : 3 }
let object2 = {id : 3 }
#

And put them in a map

#

As this

#
map.set( object1 , true )
map.set( object 2 , false )
#

U will get only false

distant gulch
#

because it overwrites it?

amber granite
#

Yep

#

So what didn't u understand fornow?

distant gulch
#

hmm, they save the objects, datas in RAM right?

amber granite
#

Yep

distant gulch
#

and they must be founden by an id right?

amber granite
#

Yep

distant gulch
#

every variable haves a different one

amber granite
#

What do u mean by id ?

#

If id in the first one was = true

distant gulch
#

i mean if the codes needs like variable2, it needs to get them by an id or not?

amber granite
#

Elaborate

distant gulch
#

it can't just say

this is variable_2
23193981298312333129383290233
amber granite
#

Yes

distant gulch
#

it must declear it for the pc so the pc can get it in the RAM

#

declare*

#

or identify

amber granite
#

Yep

#

I didn't understand XD

distant gulch
#

variables are getting saved in the RAM

amber granite
#

Yep

distant gulch
#

and somehow the script or pc needs to get them from the RAM when its needed

amber granite
#

Yep

#

But ram is fast

#

And the js engine is optimised

#

So u can't feel that

distant gulch
#

but the script can't just say, this 139328328127371224847124 value in the RAM was from the variable, it needs to mark it somehow as variable_2 with an id or somewhat like that

amber granite
#

Yep

distant gulch
#

so every variable is marked with something like an id

amber granite
#

Yep

#

Ofc

distant gulch
#

so js could easy do like

obj === obj // true, same identifier
amber granite
#

Yep and no

#

Obj === obj

#

Is not what u think

#

It s based on something called refrence

#

U need a function to compare objects

#

And libraries

#

But yes

distant gulch
#

but didnt you said like:

const obj_1 = { id: 3 };
const obj_2 = { id: 3 };

const myMap = new Map();

myMap.set(obj_1, true);
myMap.set(obj_2, false);

myMap.get(obj_1);; // would it be true or false
amber granite
#

Yeah but fhe value

distant gulch
#

does the object gets stringified there?

amber granite
#

I don't know the rxactly method

#

But u can say that

distant gulch
#

hmm okay that's why the value would be false

amber granite
#

Wait a min

distant gulch
#

Sure

amber granite
#

Can u wait ?

#

Yeah

#

As u said ur true

#

I just forgot about the refrences

#

@distant gulch

distant gulch
#

Hmm?

amber granite
#

Ur true

distant gulch
#

about what?

#

that the value would be false

amber granite
#

No will be true

distant gulch
#

huh

amber granite
#

Because those objects are in variable

distant gulch
#

yes

amber granite
#

If not in variable

#

U will get false

distant gulch
#

Hmm because by variable, it haves a lke different identifier=

amber granite
#

Ffff

distant gulch
amber granite
#

No ur true

#

Even without variables

#

Two objects are not the same

#
const myMap = new Map();

myMap.set({ name: 'Alice' }, 'Value for Alice 1');
myMap.set({ name: 'Alice' }, 'Value for Alice 2');

console.log(myMap.size); // Output: 2
distant gulch
#

hmmm

amber granite
#

It s complex i know

distant gulch
#

when i would use two different variables, it would be still 2 ?

amber granite
#

Yes

#

But

#

If u tried like

#

map.get({name: 'alice'})

#

U will get the second value

#

Value for alice 2

distant gulch
#

huh

#

but hoow can i get the first one

amber granite
#

Wait

distant gulch
#

sure

amber granite
#

XD , i hate maps

#

U will get undefined

distant gulch
#

i love them

#

huh

neat hound
amber granite
#

^

distant gulch
#

Alright, Thanks Niki

#

Nikki*

amber granite
#

U must learn something called refrence

#

It will be very handy

distant gulch
#

they are just saying like, the data is there

distant gulch
amber granite
#

But u can't get it

#

Because u like ,

#

Putted new object in it

#

It s different from the last two ones two

distant gulch
#

yes because the like "pointer" arent the same

amber granite
#

But u can get the data

#

Using forIn loop

neat hound
valid ice
#

Stringify each and compare if you wish.

amber granite
distant gulch
neat hound
#

no videos

distant gulch
#

ohh then good

amber granite
#

I have good source two

#

I learnt from it

#

If u want

neat hound
#

well, I mean they have some, but not for classes of this...

distant gulch
#

i used SoloLearn and w3schools

amber granite
neat hound
#

I did not learn from them, but they are my reference when I forget or need another way to do something. They give as many ways as possible

distant gulch
#

Nice, and btw

amber granite
distant gulch
#

DynamicProperties are being saved in the HDD/SDD right?

amber granite
#

In world UID

#

But yes the world UID is getting saved

#

In hhd and ssd

neat hound
amber granite
#

Same thing

neat hound
#

if on your PC, then your PC with the world

distant gulch
#

okay as i thought, so i could just use getDynamic.... permamently to get datas, but that would be slow right?

neat hound
#

they limit what you can store.... string, number, boolean, vector3... that is it

neat hound
#

the other database thing is different.. no exp with that yet

distant gulch
#

The maximum char limit was 32767 right? or was it the maximum amount of Bytes

amber granite
#

Yep

#

Length or byte

valid ice
#

All things considered they’re decently fast.

distant gulch
valid ice
#

It’s based off of quick js

distant gulch
#

and quick js is just js but in faster?

valid ice
#

It’s one of many available engines for JavaScript

hardy tusk
#

The fact native apis are slower than an emulated language 😭

amber granite
rugged tinsel
distant gulch
#

okay okay

distant gulch
rugged tinsel
#

that's just how these things work

#

can't really get around it

hardy tusk
#

But thats on them

valid ice
hardy tusk
distant gulch
#

same, never needed it

distant gulch
rugged tinsel
hardy tusk
#

Node is much faster if you use native api's, and apis from c++ node packages, because it aint suck

rugged tinsel
#

though honestly, the engine's not that bad performance-wise when you're only doing js stuff, it's once you start calling APIs that it starts to die

hardy tusk
#

It goes to show how good it can actually be

rugged tinsel
#

NodeJS gets to use JIT and such

distant gulch
#
const cachedString // "<keyName>:<pointer_to_index_in_data>"
const values // "datas, datas..."
#

could i save it like that

hardy tusk
distant gulch
#

cachedString contains the keys and the "pointer" or "adress" to get the datas

rugged tinsel
#

it probably has an impact to some degree

#

haven't researched the topic, but that's just my guess

hardy tusk
#

unlikely, maybe very small impact

amber granite
#

They will be slow asf

hardy tusk
#

Insignificant enough to not play a role in the argument

distant gulch
#

uhm kiroo

amber granite
#

?

#

The net get cutted off again

valid ice
distant gulch
#

Can i do it like that Kiro?

const cachedString // "<keyName>:<data_address>"
const values // "datas, data..."
neat hound
#

yeah... cause of yall.... LOL

hardy tusk
distant gulch
valid ice
#

Chars

rugged tinsel
#

did they ever address their reasoning for choosing quickjs? I can't recall

distant gulch
#

good

distant gulch
#

yes

amber granite
#

Use let

hardy tusk
amber granite
#

Because cachedstring get changed

distant gulch
#

Right right

amber granite
#

EveryTime u loded again

distant gulch
#

does people exists who* are using var ?

amber granite
#

Wh ?

distant gulch
#

who*

amber granite
#

I didn't understand, can u reask again

distant gulch
#

Does People exists, who are using the var syntax? instead of const or let

amber granite
#

Oh var used for js in the olds times

#

But no one use it for now

valid ice
#

I’m sure folks use it nowadays

amber granite
#

Except somethings

distant gulch
#

let and const where from ES6 right?

amber granite
#

Maybe

#

But u can make usage of it too

distant gulch
#

you said

> Use let

> Because cachedstring get changed

> EveryTime u loded again

but let gets also cleared ?

valid ice
#

People do goofy stuff with their code. var is like, one of the less weird things.

amber granite
#

Like getting variable out of block scopr

distant gulch
#

okay good

amber granite
#

Const var ,
Is something will get error

#

Every time u try to load new data

#

Into ur string

#

Because const is for static variable

distant gulch
#

right, because const must be declared

amber granite
#

Like PI

#

Yeah

#

Another question?

distant gulch
#

Hmm let me think

#

i guess i bothered you enough

amber granite
#

No

#

I love helping ppl

distant gulch
#

Nice

amber granite
#

What ☠️

distant gulch
#

Okay then

#

nothing

amber granite
#

Yeah so

distant gulch
#

never said anything

amber granite
#

Don't use maps because u won't need them as I KNOW

distant gulch
#

okay

#

and they are using too much of my RAM

amber granite
distant gulch
#

i got some threshhold warnings with my last database

#

> 16 MB or something like that

amber granite
#

☠️

#

Ram or Storage?

distant gulch
#

i was using Map

amber granite
#

Yes

distant gulch
#

so Ram

amber granite
#

For that u need string instead

distant gulch
#

yes ill try it to make

amber granite
#

Because it s ram friendly

#

If u got another problem

#

Tell me

#

When making ur db

distant gulch
#

ill save datas like that

world.setDynamicProperty(`[${databaseId}]${key}`, DATA_STRING)
amber granite
#

Good

distant gulch
#

and getting them like

cache += key:address
values += DATA_STRING
amber granite
#

Wait

distant gulch
#

yes

amber granite
#

What is jey:address ?

distant gulch
#

jey?

amber granite
#

Key

distant gulch
#

its the key and the address, address contains the start and end index in values from the value i will stringify

distant gulch
amber granite
#

Ahh

#

Use Stringifiy

distant gulch
#

maybe ill ad the type of the value, so i can make it more precise

amber granite
#

Stringify the object

amber granite
#

Do u mean the value in the object? Property?

distant gulch
#
// keyName:(0,23,string)...
// values: "\"this is a string",2,12,...."
amber granite
#

Oh noo

distant gulch
#

?

amber granite
#

Not that way

distant gulch
#

okay?

amber granite
#

That will kill ur pc

distant gulch
#

this isnt a object btw

amber granite
distant gulch
#

that are two string, wait

amber granite
#

So u will saves keys on a string

#

And the values on another string

#

Then what !!!

hardy tusk
# distant gulch i actually use them

Yes the was more about how, when you're in a switch statement, you cannot do something like

switch(arg[0]) {
case "kick":
let player = getPlayer(arg[1])
player.kick()
break;
case "invite":
let player = getPlayer(arg[1])
sender.invite(player)
break;
}

This wouldnt work

#

And its horrible

#

You would have to use var, or wrap all the entries in the switch statement in {} brackets who use that variable name

amber granite
#

What about putting
Arg[0] value on a variable

amber granite
#

Way. , My bad

distant gulch
#

@amber granite

// key : ( startIndex, length, type )
let addresses = "PI:(0,5,number),PI2,(6,5,number),A_STRING(12,8,string)"
// value,value,value...
let values = "3.141,6.282,a string"
hardy tusk
#

And this is because when you are in a switch statement, it considers all case's to be on the same level, because technically 2 case could execute after another

distant gulch
#

like that

distant gulch
#

I will be right back, crying on toilet

amber granite
#

What da

#

I m shocked

hardy tusk
#

Which is honestly really stupid, because the only time this would make sense is when you have a variable declared in a case and then want the switch to match the 2nd case you could use that variable in the 2nd case, but that is A TERRIBLE practice and should never be done and you can also just declare the variable outside the switch and assign an value to it, so the entire idea of this is completely useless

distant gulch
#

im back

amber granite
#

Bro just stringify ur object

hardy tusk
distant gulch
distant gulch
amber granite
distant gulch
amber granite
#

Hmm , ok

distant gulch
#

and they just added to the strings

#

the addresses and values

amber granite
#

Yes then ?

distant gulch
#

And i can't use JSON.stringify on a number so i added the type of the value so i can use the right function to get the value of it

amber granite
#

Bro

#

Json stringfy is only for object

#

Even if proprety was a number

#

Or true or false

#

It just takes the object and put two qoutes

#

On every key and value on it

#

And when u parse it

#

U will get the object again

#

As it was

distant gulch
#

wait a sec

amber granite
#

XD bro choses to think harder and work dumber

distant gulch
#

lol i didnt knowed that json.parse can even parse simple string values lol

amber granite
#

👀

distant gulch
#

i tought it only were for Objects

amber granite
#

Yeah for objects

#

Try this

distant gulch
#

ive tested it rn

amber granite
#

{ id : 5 , pd : true , is : "jeje" }

distant gulch
#

right,... Number, String and Booleans are objects

vocal elbow
#
let mainhandItem = event.source.selectedSlot;
event.source.runCommandAsync(`say ${mainhandItem}`);``` why doesn't it returns me 'undefined'
#

?

distant gulch
amber granite
#

Bro

#

The true , false etc...

amber granite
#

Don't get quoted

#

And when u parse them

#

U will get the value

#

And his type

#

Again

distant gulch
#

but selectedSlotIndex does @vocal elbow

#

@amber granite sooo

#

should i save it like that:


// key:startIndex,length
let addresses = "PI:0,5,PI2:6,5,A_STRING:12,8"
// value,value,value...
let values = "3.141,6.282,a string"
amber granite
#

No

distant gulch
#

and slices them by the addresses

#

okay?

amber granite
#

U should save like that