#Script API General
1 messages · Page 2 of 1
hmm okay
for ( let i = 0 , i< array.length ; i++ )
so for veryyy big arrays
const arrayLength = myArray.length;
for (let index = 0; index < arrayLength; index++) {
// ....
};
??
Yep
Use forEcah for small arrays , because it s faster to write
And tge impact is very small
that's not a good argument
but when the perfomance doest decreases i would use more array methods
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.
array.filter(...).map(...)
sometimes i use a loop instead of two array methods
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?
U can put it in a variable
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)
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
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
hmm okay
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
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
do yalls know how we can use other programming languages with js
Or wait until Minecraft uses lua. instead of js
Libraries
"jsons" files
Frameworks
ok
It needs well programming knowledge
i can work on it
c++ classes are way easier for me to make
What type of linking do u need ?
ooo
if transpliers exist
it is possible to make a replica of the minecraft enviroment in c++
¯_(ツ)_/¯
... if you asking this because you don't want to learn js, learning js would probably be easier than doing that for you
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)
Hello! What's the latest version of @minecraft/server?
Thanks! 
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))
wouldn't that be correct?
Going off of the @minecraft/server npm page, the latest stable is 1.11.0, with the latest beta being 1.14.0-beta.
I see, thanks again!
The results may vary on each device
They may. I tested this on Windows 11, v1.21.1.
help finna
Give me the code u usex
is dosent work for some reason
The error
wait
What the error that got logged
In console
It s syntax error
If u got SyntaxError that means u didn't close paranthes
Or curly braces
it issss
?
Is this the code
?
Wait i will fix
U must add }) in the end of the code
I know
world.beforeEvents.itemUse.subscribe(data => {
let player = data.source
if (data.itemStack.typeId === "minecraft:recovery_compass") {
system.run(() => {
main(player)
})
}
})
Do u use IDE ?
I tried to do it again and it worked
When someone asks for help here everybody rush to help XD
xd
That s funny
reminds me of someone
Of what?
a guy
a guy, but who
a guy
who made their code with like
fuckleton of if else
Has anyone made a hunger meter for items?
I don't suppose someone knows why this is failing
enchantable.addEnchantment({ type: EnchantmentTypes.get('piercing'), level: 1 })
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
That's odd considering I'm checking if it can be added enchantable.canAddEnchantment()
I think that might be what's throwing the error tbh
I do have multishot also being added, forgot those were incompatible. Going to remove that and check
Yeah that solved it
Thanks
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.
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?
Yeah it's given it with the level
And I don't have piercing being added anywhere else
There is no way to have constantly updating server forms, correct?
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
You'd have to close and open a new form
how do i replace the item in my offhand with an item that canot be moved and is slot locked?
i forgot
And one would have to do that manually, right?
Yes
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?
What ?
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?
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
Oh
Because playerInte , is in beta api only
Im aware...
is it correct?
What the error that appears?
Are u sure ur using beta api ? @solar dagger
I don't think so
Send me the manifest
And turn all experimentals
havent tested yet
doesnt it go instant than? mightve missed smth
i fixed it nvm
Don't use async
why?
It s not useful in this situation
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
Just do item.lockMode
or do newItemStack thingy
oh ok
wait
but for that i would need to do an new item stack right?
No
oh ok, leme try than
Oh I see what’s going on
You’re setting item variable to a string. A string does not have the lockMode property.
oh, so what do i need to do in order to fix it?
And itemName would be undefined, as it doesn’t exist in the code you sent
Idk what you’re wanting to do
? Elaborate
i wana do an item switcher
like atm its not working cuz the item variable is an string
ahh, i knew it
let item = new ItemStack(offhandItemStack.typeId.replace('_off', ''), 1);
item.lockMode = "slot";
source.getComponent('equippable').setEquipment('Offhand', item)
Yes
But what id item.lockMode ?
It s a string
Not an object
To make a proprety to it @fading sand
?? I thought its an item stack now
how?
yes, but item stack
Hello
Not
No it a type i
Id
That s not how js works
Xd
I want to make a Database with DynamicProperties, should i add a chache where the gotten data gets stored?
Yeah i made that
With new Map() or Array
I can't explain it frnow u don't have the required knowledge
Wait...
but people do it like this:
new ItemStack('minecraft:iron_sword', 1);
im confused..
Item dynamic properties
Yes that s better
item.setDynamicProp
and item is the string?
New itemstack
Item.lockmode
Item. Blah blah
SetItem(item)
but thats what i did
Did it work?
Object.defineProperty(ItemStack, 'key', {
enumerable: true,
writable: true,
set: (v) => {},
get: () => {}
})
maybe with that
let item = new ItemStack("${offhandItemStack.typeId}_off", 1);
item.lockMode = "none";
source.getComponent('equippable').setEquipment('Offhand', item)```
no
I can't focus °-°
Are you doing this in a before or after event?
Guys, when i want to make a cache with key and value, should i use the Map class
okay good
But
yes
after event
What are trying to do
A DataBase and i want to put the gotten datas in a cache
Key and Value ( value as string and normal )
Is it deep object data ?
Or just shallow one
const data = {
key: string|number|boolean,
value: {
encoded: any,
decoded: string
}
};
deep i would say
yes i want to do it like that
i remeber now, i dont need encoded or decoded
yes i know the method
but i just want to know, should i cache all the gotten data
If the data is big!!
sometimes
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
i think you are missunderstanding me
U are talking about loaded data right?
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
U means
Getting them from ram or rom
Because getDynamicPropreties uses rom and it s slower
Hmm okay
And making it into a variable = cache it in ram
U need to Making it in a Variable if u want real fast result
what do you mean by variable, a map? like
const cache = new Map();
No just a regular variable
I told u u need to stringify it
how should i be able to storage all the datas form the database in one variable
'/"the stringified object"/"the next one"/'
same
But making the object as string is better for ur ram
Instead of using map
Because that will takes a lot of ram
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
And if u want to get an object u can just search in that string
How to repair item with script 🤔
And get the object and parse it
imagine parsing a 32k chars string
U can because it s ram friendly
No
Get the durability component
I mean search for ur object
I dont know can u help me code
btw is DynamicProperty always better than scoreboard?
The objects = " object1.{jej : 772 } / object2.{uehe:827} / "
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
imagine the objects haves a key what haves the same name as the key i want to get
For that u gonna get the object by name
I just used that method in my database
And it worked
isnt it a really slow mthod?
But ram friendly
And not that slow
Because the variable itself is saved in ram
And the objects are small
when i need to get fast datas, and i hav elike 500 objects in there
Yeah normal too
i have maybe less than 500 chars per object
Same bro
hmmmm
So
yes
It s the hard drive
okay
That s all XD
idk if my laptop evens haves a HD
i have an SSD storage
Okay, i dont think my Laptop haves a Hard Drive Disk because i use a SSD
The hard drive is only to store things that the system won't use them
yes
Yes and no
okay
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
you still get an array with strings, or an empty one
okay
.2 ssd
I have one SSD from Samsung build in
That what u need to know
okay nice
Are you german?
No
ah ok, so i would need to do tags[0] to get it?
Yes
alr thx
So if the data was saved in ram
cd rom
it takes longer to get or execute the data?
It takes a small time idk like 1 second , to get the data
But not a big time
so the map Class saves the datas in the RAM?
It s something linked to ur data size
Yep
U can use it immediately
So that means, Objects are saved in the RAM and variables in the ROM =
serialize?
Yep
what does that mean exactly?
never heard of it
or my English limits found their end
I must explain the computer science for u XD
So u know the data in ur script
Get deleted
After u just exit the world
Because it s saved in ram
Yes
But not in devices storage
okay
okay but why
What u mean by why ?
why should it write the data in ROM after deleting it in the RAM
U doing that by making a db u silly XD
okay okay
not really
Yes
Until the time he exist the world forever
The script can't do that without access to Rom
The storage in ur device
ii dont understand that sentence?
Sorrry either ist my english or your grammar
Using script
Yes
U can't do that with only script
Without saving the times that he died
Because u know the script is excuted in ram
yes, we need to likke storage his deaths somewhere
Yep
That somewhere called ur ROM
really? cool
Or storage
Everything works in ram
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
yes, 64gb ddr4 ram costs about 100€
As examples u find ram with 6 gb is expensive then rom with 200 gb
1TB ROM = less than 70€
64GB RAM = less than 120€
That s how computer's work
Yes
So u know the processure
I5 - intel
Or idk
thats why saving takes longer than the other shi*
I7 - 10 th
Yes
Yes
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
okay nice, btw lets continue it in dm, i need to go really fast rn
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
Sorry, be right back
Ok np
@amber granite
I don't know
backkk
Hey sorry
There some misunderstood in my messages
Rom is other type of data storage
U can't change it ever
hmm okay
okay, so read-only
okay
Not like the rom which us soliderated into the mother borad itself
okay
okay
And ram is faster for that specific thing
okay so in ROM?
Rom is other thing
read only thingy right
I told u it misunderstood from me
Yep
I mean by rom is hdd and ssd in the last speach
Because rom is something other..
so in HDD or SDD gets the code saved or executen?
Yep get saved in
What is this converstaion?
About saving datas
main theme was a database
and the variable i have, lets call it rawCache
it gets saved in the HDD / SSD ?
Yep it s saved in ram
okay ram
The ram saves everything that cpu working with
Because its faster
From getting data to setting data from and to it
Yes faster then rom and hdd and ssd
Because that it s expensive
yes
more efficiency > more expensive
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
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?
Yep
okay
okay
I mean only what u want to save and get it for later
okay
So i told u to make a variable
And put strings of objects in it
Because it saved in ram
But a Map class is also saved their
No
I mean Map allocate as examples : 32 mb
As example
In RAM
But when u use a string instead
an empty one?
No just an example
Okay
It takes more lower then that
Okay because they are two arrays that are being saved or what?
Two arrays ?
What do you mean?
I mean if u assigned proprety:
The JS object like [] or {}
object = {}
object.true = 1
Is same as
object["true"] = 1
Like {}
okay this object
yes, properties ad values
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
okay so types wont be saved, they are ending up as a string?
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()
yes
map.set(true , 5);
map.set("true" , 5 )
will the first key be overwrited by the second one?
because of different types
Yep
good
that's?
U can put an object as key
wasnt it used for WeakMap??
No
hmm okay
Weak map are for something called refrence
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?
No problem
Yes
So u see
Lemme give u example
okay but how does the code knows, if object1 === object
In Map ?
yes
That s good question
i have read that you can't just compare objects like obj1 === obj2
But i can respond it fn
no problem
- comparing objects is not like that
maybe by stringifying that object
yes?
Means they don't have the same propreties
yes, kinda
If u put the same propreties u will get the same result
Even if u have individual ones
hmm
to identify them correctly?
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
because it overwrites it?
hmm, they save the objects, datas in RAM right?
Yep
and they must be founden by an id right?
Yep
every variable haves a different one
i mean if the codes needs like variable2, it needs to get them by an id or not?
Elaborate
it can't just say
this is variable_2
23193981298312333129383290233
Yes
it must declear it for the pc so the pc can get it in the RAM
declare*
or identify
variables are getting saved in the RAM
Yep
and somehow the script or pc needs to get them from the RAM when its needed
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
Yep
so every variable is marked with something like an id
so js could easy do like
obj === obj // true, same identifier
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
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
Yeah but fhe value
does the object gets stringified there?
hmm okay that's why the value would be false
Wait a min
Sure
Can u wait ?
Yeah
As u said ur true
I just forgot about the refrences
@distant gulch
Hmm?
Ur true
No will be true
huh
Because those objects are in variable
yes
Hmm because by variable, it haves a lke different identifier=
Ffff
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
hmmm
It s complex i know
when i would use two different variables, it would be still 2 ?
Yes
But
If u tried like
map.get({name: 'alice'})
U will get the second value
Value for alice 2
Wait
sure
This is where taking the JS basics come in handy.... objects are not data, they are pointers to an address that hold the data, that is why they are not equal.. my house is not your house. You have to use other methods to compare the innards of objects... and arrays are objects too.
^
they are just saying like, the data is there
okay
Yes
But u can't get it
Because u like ,
Putted new object in it
It s different from the last two ones two
yes because the like "pointer" arent the same
I like this group of people.... they explain well and give you a space to practice. https://www.geeksforgeeks.org/javascript/
This Javascript Tutorial is designed to help both beginners and experienced professionals master the fundamentals of JavaScript.
Stringify each and compare if you wish.
That s for quick compare
thanks but i can't watch videos cause my wifi is hell right now
no videos
ohh then good
well, I mean they have some, but not for classes of this...
i used SoloLearn and w3schools
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
Nice, and btw
U can learn from that , there is gitHub version too , offline
DynamicProperties are being saved in the HDD/SDD right?
to the world, wherever it is... so if a realm, to the realm
Same thing
if on your PC, then your PC with the world
bombing the realms storage yeah
okay as i thought, so i could just use getDynamic.... permamently to get datas, but that would be slow right?
they limit what you can store.... string, number, boolean, vector3... that is it
Yep ofc
the other database thing is different.. no exp with that yet
The maximum char limit was 32767 right? or was it the maximum amount of Bytes
Dynamic properties are only slow in the sense that they are script API methods and not vanilla JavaScript
All things considered they’re decently fast.
but isnt the Minecraft API build in Minecraft?
It’s based off of quick js
and quick js is just js but in faster?
It’s one of many available engines for JavaScript
The fact native apis are slower than an emulated language 😭
Js without some js vanilla things
they're not, it's the translation between js and c++ that's slow
okay okay
they just removed eval sad
But thats on them
U won't use it tho
Eval exists, you just need a manifest thing
Yes, better engine
same, never needed it
🙂
I agree that they picked a bad engine, but with the engine they have, there's no way around it right now
Node is much faster if you use native api's, and apis from c++ node packages, because it aint suck
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
It goes to show how good it can actually be
not a fair comparison
NodeJS gets to use JIT and such
const cachedString // "<keyName>:<pointer_to_index_in_data>"
const values // "datas, datas..."
could i save it like that
Yeah but that doesnt have any impact on API calls
cachedString contains the keys and the "pointer" or "adress" to get the datas
it probably has an impact to some degree
haven't researched the topic, but that's just my guess
unlikely, maybe very small impact
But when data gets bigger and bigger
They will be slow asf
Insignificant enough to not play a role in the argument
uhm kiroo
Dynamic properties have a limit for a reason
Can i do it like that Kiro?
const cachedString // "<keyName>:<data_address>"
const values // "datas, data..."
yeah... cause of yall.... LOL
Well you can always just use js to do it for you, and save it with dynamic properties every now and then
32767 Chars or Bytes?
Chars
did they ever address their reasoning for choosing quickjs? I can't recall
good
In ur db ?
yes
Use let
I think they said because its easy to implement and get working
Because cachedstring get changed
Right right
EveryTime u loded again
does people exists who* are using var ?
Wh ?
I didn't understand, can u reask again
Does People exists, who are using the var syntax? instead of const or let
I’m sure folks use it nowadays
Except somethings
let and const where from ES6 right?
you said
> Use let
> Because cachedstring get changed
> EveryTime u loded again
but let gets also cleared ?
People do goofy stuff with their code. var is like, one of the less weird things.
Like getting variable out of block scopr
Yes
okay good
Const var ,
Is something will get error
Every time u try to load new data
Into ur string
Because const is for static variable
right, because const must be declared
Nice
What ☠️
Yeah so
never said anything
Don't use maps because u won't need them as I KNOW
Yep
i got some threshhold warnings with my last database
> 16 MB or something like that
i was using Map
so Ram
For that u need string instead
yes ill try it to make
ill save datas like that
world.setDynamicProperty(`[${databaseId}]${key}`, DATA_STRING)
Good
and getting them like
cache += key:address
values += DATA_STRING
Wait
yes
What is jey:address ?
jey?
Key
its the key and the address, address contains the start and end index in values from the value i will stringify
i actually use them
maybe ill ad the type of the value, so i can make it more precise
Stringify the object
Ahhh
Do u mean the value in the object? Property?
// keyName:(0,23,string)...
// values: "\"this is a string",2,12,...."
Oh noo
?
Not that way
okay?
That will kill ur pc
this isnt a object btw
What u gonna save ?
that are two string, wait
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
What about putting
Arg[0] value on a variable
my eyes
Way. , My bad
@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"
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
like that
What da
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
im back
Bro just stringify ur object
Im on phone, not gonna do indentation lol
okay
but i wasnt saving an object
U was saving propreties?
that are single example values i saved like a number, another number and a string
Hmm , ok
Yes then ?
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
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
wait a sec
XD bro choses to think harder and work dumber
lol i didnt knowed that json.parse can even parse simple string values lol
👀
i tought it only were for Objects
ive tested it rn
{ id : 5 , pd : true , is : "jeje" }
right,... Number, String and Booleans are objects
let mainhandItem = event.source.selectedSlot;
event.source.runCommandAsync(`say ${mainhandItem}`);``` why doesn't it returns me 'undefined'
?
no i made
JSON.parse("true");
https://jaylydev.github.io/scriptapi-docs/latest/classes/_minecraft_server_1_11_0.Player.html#selectedSlotIndex selectedSlotIndex
Don't get quoted
And when u parse them
U will get the value
And his type
Again
player.selectedSlot
```shouldnt exists
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"
No
U should save like that