#Have this script, wont work with new update, any way i can fix it, i dont script
1 messages · Page 1 of 1 (latest)
I was planning to release my realm this Friday but I guess plans change, just need it as fast as possible
(node:22) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/jail/prog.js:1
import {
^^^^^^
SyntaxError: Cannot use impor
There are 2 errors in this [code](#1100963388173070358 message):
[36mindex.js[0m:[33m34[0m:[33m11[0m - [31merror[0m[30m TS2740: [0mType 'Entity' is missing the following properties from type 'Player': level, name, onScreenDisplay, selectedSlot, and 16 more.
[7m34[0m const player = data.source
[7m [0m [31m ~~~~~~[0m
[36mindex.js[0m:[33m48[0m:[33m37[0m - [31merror[0m[30m TS2552: [0mCannot find name 'MoneyTransfer'. Did you mean 'moneyTransfer'?
[7m48[0m if (result.selection === 1) MoneyTransfer(player)
[7m [0m [31m ~~~~~~~~~~~~~[0m
[36mindex.js[0m:[33m109[0m:[33m7[0m
[7m109[0m const moneyTransfer = (player) => {
[7m [0m [36m ~~~~~~~~~~~~~[0m
'moneyTransfer' is declared here.
There are 7 errors in this [code](#1100963388173070358 message):
[36m@minecraft/server-editor.d.ts[0m:[33m11[0m:[33m10[0m - [31merror[0m[30m TS2305: [0mModule '"@minecraft/server"' has no exported member 'Events'.
[7m11[0m import { Events, Player, System, Vector3 } from "@minecraft/server";
[7m [0m [31m ~~~~~~[0m
[36mindex.js[0m:[33m29[0m:[33m7[0m - [31merror[0m[30m TS2339: [0mProperty 'events' does not exist on type 'World'.
[7m29[0m world.events.beforeItemUse.subscribe(data => {
[7m [0m [31m ~~~~~~[0m
[36mindex.js[0m:[33m48[0m:[33m37[0m - [31merror[0m[30m TS2552: [0mCannot find name 'MoneyTransfer'. Did you mean 'moneyTransfer'?
[7m48[0m if (result.selection === 1) MoneyTransfer(player)
[7m [0m [31m ~~~~~~~~~~~~~[0m
[36mindex.js[0m:[33m109[0m:[33m7[0m
[7m109[0m const moneyTransfer = (player) => {
[7m [0m [36m ~~~~~~~~~~~~~[0m
'moneyTransfer' is declared here.
[36mindex.js[0m:[33m121[0m:[33m40[0m - [31merror[0m[30m TS2538: [0mType 'false' cannot be used as an index type.
[7m121[0m const selectedPlayer = players[dropdown];
[7m [0m [31m ~~~~~~~~[0m
[36mindex.js[0m:[33m121[0m:[33m40[0m - [31merror[0m[30m TS2538: [0mType 'true' cannot be used as an index type.
[7m121[0m const selectedPlayer = players[dropdown];
[7m [0m [31m ~~~~~~~~[0m
[36mindex.js[0m:[33m126[0m:[33m25[0m - [31merror[0m[30m TS2339: [0mProperty 'includes' does not exist on type 'string | number | boolean'.
Property 'includes' does not exist on type 'number'.
[7m126[0m } if (textField.includes("-")) {
[7m [0m [31m ~~~~~~~~[0m
[36mindex.js[0m:[33m130[0m:[33m13[0m - [31merror[0m[30m TS2365: [0mOperator '<' cannot be applied to types 'number' and 'string | number | boolean'.
[7m130[0m if (getScore('money', player) < textField) {
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
So how do I fix that? I don’t know how to code, it was given to me
Is this the fixed one?
I don't know
So you tried to fix it and that’s the attempt I’m guessing?
The form opens and I don't think there's an error
Well, after the update I can’t even open the gui like I normally could
Send your manifest.json
Send your manifest.json:
manifest.json file is a file that contains information about a data pack. A data pack is a collection of files that can be used to customize Minecraft gameplay mechanics, such as adding new crafting recipes, modifying loot tables, or creating new advancements.
The manifest.json file contains metadata about the data pack, such as its name, description, and version number. It also lists the files that make up the data pack and specifies their location within the file structure. Minecraft uses this information to properly load and enable the data pack in-game.
Yeah, then that should be in what I already sent
I cannot se one
If you want me to, I can send you the entire file and compress it to a zip file so I can send it
Yes, Send your files
Will do! Getting on my computer right now!
i didnt compress it to zip, it is letting me send normally
oh well its multiple files if that makes sense, it didnt send as normally
oh now i see the manifest
I believe you need to change the version to 1.2.0-beta: {
"module_name": "@minecraft/server",
"version": "1.1.0-beta"
}
I also believe this fixes it:
so if i use that, it should work?
I believe so:
alright ill check!
also another question
sorry
so when i want to replace the behavior pack with a newer version, it doesnt update, like the changes arent made, is there a reason for that?
Where did you put the new file?
i always put it in behavior packs
It is recormended that you packs into development folders
You should move the pack from the world folder
well its in a realm, not in a world
so whenever i replace it in developement folder, it should be updated with the new one?
Your going to need someone that know there stuff with realms
well, what if i just download a backup and do it on the world then put the world in the realm
I believe so
okay, and you said put it directly onto the world
yeah i checked it has, now i just need to get the world then put it in the world
do i remove the older one from my packs?
Yes, Just download the one I sent and put your older one on your desktop and add the new one
Don't delete just in case something goes wrong
okay, so just to make sure, i take the older one put it on my desktop and the new one, instead of putting where the old one was, i put it directly into the world
Yes
alright
So your manifest changes are reflected onto the world
alright, well there are no development bahavior packs for the world just normal behavior
Ok, Just use what you would normally use
alright
behaviour_packs
Excellent!
dude thankyou sm for helping me btw, you have no idea
do i just load into the world and see if it works?
Yes, Run your code like you have done so as normally
alright
I will try your pack
i dont know
I just imported your fixed pack
i think the problem for me is, the pack never gets removed from "my packs" the older one ofc
i remove it, it just stays there for some reason
Delete your pack altogether and import this newer one:
okay, how would i do that, cause the one that is in behavior that shuldnt be is already gone
Go to your packs > behaviour > click the pack we are talking about > look for a red X button > click it
In game
On realm settings
alright
so it doesnt pop up in my realm stuff, only pops up in my world
like in my packs
and there is no x
So your newer pack is working on your local world?
no
Download your realm back-up and delete the old pack
And import the new pack and apply it to this world you downloaded and add it to there, Upload this new world to the realm
I will check
alright!
Make the code cleaner to look at and use better method of doing stuff in the gui
i mean anything that helps would be great lmfao, and if possible ofc, could you make sure money transfer would work with a scoreboard objectives money lowercase m
oh then yes please
Yes!
thankyou sm
Using that instead of functions
sure!
Also I believe I found an error for why your money transfer won't open: .body('') you have not use any strings for this function
You must provide one: §r
oh alright
will i be able to use it with a scireboard objectives money strictly lowercase m lmfao
Yes, You can us dthe build in function: example.toLowerCase();
Also I found a type: MoneyTransfer instead of: moneyTransfer
oh that may have been the problem
I believe is parses the results
Well this is an opportunity for you learn new stuff!
yeah!
do you think it would make i easier and better?
are you able to test it whenever you finsih it to see if the money transfer works with a scoreboard of money
@azure osprey
Yes, I'm still here doing it, It took so long as I don't have a computer, But you will be laughing when you see your new code
Lmfao why will I be laughing
oh my god thankyou
dude, your helping sm right now man, i thought i would have to delay my realm release
does it work?
Hi @lean dune ! Just a heads up these APIs break all the time. It sounds like you have an interest, so I recommend watching the main chat and picking up a tutorial on Javascript basics. Don’t be intimidated by it though. It’s totally something you can learn even if you didn’t have a computer science background.
ive tried to look at things like that, and i just seem so stupid compared to that, i have no idea what any of that does means nothing, i would have to do everything x5 to remember it
just slightly remember it
It’s really tun to learn and experiment with and these skill can be very useful later on with other API work in the professional setting as well.
ill definitely give it a try! but i really dont know where to start
I felt the same way about three weeks ago and it’s all starting to click now. Start saving snippets of working code from the main chat to reference and try a small but of code from scratch, like a “hello world” or something.
alright! ill give it some thought for sure lmfao, if i ever have some free time ill definitely try it out
Here’s something that covers general Javascript: https://exploringjs.com/impatient-js/toc.html
okay! thankyou
And here is the root directory for Microsoft’s API, which adds additional functionality to vanilla Javascript: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/
ill take a look for sure!
And Bedrock.dev is the last thing I’ll bother you with: https://wiki.bedrock.dev/scripting/scripting-intro.html
alright lmfao, if i ever have some freetime ill try learning it!
😺
defowler is it possible to have a timer for warps?
that might be too much to ask, if it is thats fine lmfao no need to do it ofc
(node:22) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/jail/prog.js:1
import {
^^^^^^
SyntaxError: Cannot use impor
There are 4 errors in this [code](#1100963388173070358 message):
[36mmain.js[0m:[33m30[0m:[33m25[0m - [31merror[0m[30m TS2339: [0mProperty 'player' does not exist on type 'BeforeItemUseEvent'.
[7m30[0m const player = data.player;
[7m [0m [31m ~~~~~~[0m
[36mmain.js[0m:[33m111[0m:[33m9[0m - [31merror[0m[30m TS2304: [0mCannot find name 'discordCode'.
[7m111[0m discordCode.title("§l§9- Codes -§r");
[7m [0m [31m ~~~~~~~~~~~[0m
[36mmain.js[0m:[33m112[0m:[33m9[0m - [31merror[0m[30m TS2304: [0mCannot find name 'discordCode'.
[7m112[0m discordCode.textField('§l§dDiscord Join Code§f: §9rMqcCGMQhv\n\n§l§9Enter Discord Code Below',
[7m [0m [31m ~~~~~~~~~~~[0m
[36mmain.js[0m:[33m114[0m:[33m9[0m - [31merror[0m[30m TS2304: [0mCannot find name 'discordCode'.
[7m114[0m discordCode.show(player).then((r) => {
[7m [0m [31m ~~~~~~~~~~~[0m
i think i know the issue
What is it!
i dont think the issue is with the GUI
i think the issue is with my add-on!
instead of trying to remove their money with scoreboard commands or add their money with scoreboard commans try ths
this
/tag add @initiator "money:500" that would be to add the money
to remove its like this
/tag add @initiator "money:-500"
or whatever @ you would use
${selectedPlayer}?
Idk, however you would add the money
Ik for me in game if I want to add money to myself it’s
There's a addScore function
/tag add @s “money:amount”
Use it?
Well to add money using the add-on I use you can test if they have enough money using scoreboard
But can not remove it, rather remove it using /tag add @s “money-500”
“money:-500”*
So to test their money you would still do /scoreboard players test @s money then the amount
But to remove such money you would use the tag
Does that make sense?
Ok. I have come to the conclusion that the error is not an actual error: it's a bug, I remove the transfer money from the script and the error is still here!
hmmm
Otherwise I'm just bad
does it say where the error is?
Yes I will go grab it
[Blocks][error]-failed to read file data
[Blocks][error]-failed to read file data
[Scripting][error]-TypeError: Unexpected type passed to function argument [0]. at home (main.js:44)
at <anonymous> (main.js:32)
so moneytransfer just wont open at all?
Correct! Also the error pops up upon opening the home form
Also the line numbers are incorrect
alright well he just got online so maybe he sees our messages
@limber gulch may we please use your help
Hi.
so we have an error in the code i believe and we dont know how to fix it
Which file is it? The “main.js” above?
@azure osprey thats all him to be honest
Or Template_GUI…
The BeforeItemUse error is probably something related to the 1.19.80 changes, and I’m not fully up to speed on those related changes
The discordCode error
hmm, is there a way to know what changed
There’s a function “discordCode”
like what to change in the code because of the update
And a variable “DiscordCode”
yeah
The wrong name was used for the variable I think
hm, so what would @azure osprey do
I personally would delete the whole file and redo all of it
Yes
i didnt make this, i dont know ho to code
Ok, How about I remake this whole thing?
are you sure...?
Yes!
how long would this take?
I have the time
how many days would it take?
Maybe 20m to 1h
oh, thats not too bad actually
alright, im fine with it. i mean thankyou a lot. just remember the tag stuff for money transfer
and coordinates for warp and all that
Here, Send me your world so all stuff can be reused
A solid act of kindness! 🫡
I wouldn't call it solid
@lean dune This is how I got started with APIs. I had an addon that I liked. It broke with an update and I got frustrated being stuck and had to learn this stuff so I wouldn’t have to wait on the authors to maybe get around to re-publishing.
thats cool!
i have a quesion alec, do you know a way that without using @p do a command for someone if they did something but they didnt "initiate" the command
so not @initiator either
so to be specific i have a npc, i want to use it as a shop command. so right now i have it setblock next to a command block as a redstone block to activate the command. but i have no way to test them without using @p since they didnt initiate the command, the npc did
chat commands?
what are these? like script like what we are doing for the GUI
amazing idea. but the time that would take would be sickening
I already have one
Commands and command blocks can be squirrelly, since you have very limited functionality and have to get creative to find a solution.
hmmm
You’ll like the API solution better
That's where JavaScript comes in
Easy way to learn is to get something that works to start with
because my shops are huge
like there are over 50+ things that you can buy
and will be able to sell
And when something breaks it in a minor update, read the changelogs and try to fix
Javascript handles that sort of thing very well
but thats a lot of coding
The code could be simple enough and the bulk of it would be data entry for the items and associated values
And if you set it up carefully, you can keep your files neat and readable
hmmm... i guess its all up to @azure osprey i feel like if we did have that it kind of would help my realm stand out from others, because no other realm has a virtual buy/sell
Look at the import/export stuff in the first Javascript manual I sent
You’ll be able to have all your items and values in a separate file
alriggt
And be able to import them into your main shop code
So, We making a custom cmd?
a custom cmnd?
Custom command builder: DLL.sell iron 28
couldnt we just have it in the UI?
like right click the UI, then click shop, sell, the type of item, so if its wheat then farming
then select the amount, sell
is that possible?
Right clicking, No
well interact
just like the GUI does now
to access it, i have to right click
or "interact"
How about I send a basic server script pack containing cmd builders, gui
sure! ill go on a test world and see what your proposing
So, first lets make the cmd builder!
Here:
import {
world,
Player,
system
} from '@minecraft/server';
const config = {
prefix: 'DLL.';
}
class commandBuilder {
constructor() {
this.registeredCommands = [];
}
create(info, callback) {
this.registeredCommands.push({
name: info.name.toLowerCase().split(' ')[0],
description: info.description ?? undefined,
usage: info.usage,
permission: info.permission,
callback
});
}
remove(command) {
const index = this.registeredCommands.findIndex(cmd => cmd.name === command);
if (index !== -1) {
this.registeredCommands.splice(index, 1);
}
}
forEach(callback, thisArg) {
this.registeredCommands.forEach(callback, thisArg);
}
clear() {
this.registeredCommands = [];
}
};
const command = new commandBuilder();
world.events.beforeChat.subscribe((data) => {
try {
const {
message,
sender: player
} = data;
if (!message.startsWith(config.prefix)) return;
const args = message.trim().toLowerCase().slice(config.prefix.length).split(/\s+/g);
const cmd = args.shift()
const cmdData = command.registeredCommands.find(c => c.name === cmd);
data.cancel = true;
if (!cmdData) return player.sendMessage(`§cInvalid command! The command '${cmd}' does not exist.`);
if (cmdData.permission && !cmdData.permission(player)) return player.sendMessage(`§cInvalid permission! You do not have permission to execute the '${cmd}' command.`);
cmdData.callback({
player,
args
})
} catch (error) {
console.error(error);
command.clear();
}
});
whats this
Cmb builder!
const gui {
main: ((player) => {})
};
command.create({
name: 'gui',
description: ''
}, ({
player,
args
}) => {});
this is a part of the other one?
This is the command creator/regester
alright
command.create({
name: 'gui',
description: ''
}, ({
player,
args
}) => {
//Your everyday code here!
});
so are you just kind of dumping all the code your making for it here?
Yes
alright!
Oh no it's 1:34!
huh?
Its past my sleep schedule
oh!
Ok, Last questions?
yes! do you have the script with the moneytransfer fixed?
or are we still fixing that?
yeah! alright, and are we building the shop into the GUI?
like the buy/sell for everything
Ok, We first need our: waitMove function as the player may still be in the chat, The rest of the code will be executed after the player has moved
okay, so we will be having a buy/sell shop in the GUI
Definitely
okay! well thankyou again! do you know when youll be back your time?
Yes, Around 10:00AM
so my time, idk lmfao
What time zone?
Example: @azure osprey get online
Take this for self assurance: https://github.com/JaylyDev/ScriptAPI/blob/main/scripts/compass-prompt/index.js
alright
i have an idea! chest UI! ill tell you ab it when your awake
This stopped working. Ive already changed the manifest to reflect the update. Now im teying to find all the changes i need to make. This isnt worki g now.
import { world } from "@minecraft/server"
world.events.projectileHit.subscribe(eventData => {
const {
source,
projectile,
blockHit
} = eventData
if (!source.hasTag("gamer")) return;
if (!blockHit) return;
const { block } = blockHit
let power = block.getRedstonePower()
if (power >= 14) return;
// code here when player has tag and power is 14
{
source.runCommandAsync(`function getkey`)
}
})```
There is 1 error in this [code](#1100963388173070358 message):
[36m<repl>.js[0m:[33m7[0m:[33m5[0m - [31merror[0m[30m TS2339: [0mProperty 'blockHit' does not exist on type 'ProjectileHitEvent'.
[7m7[0m blockHit
[7m [0m [31m ~~~~~~~~[0m
let a: ProjectileHitEvent;
a.getBlockHit()
No errors in [code](#1100963388173070358 message)
Do I add that and remove the blockhit from the const?
import { world } from "@minecraft/server"
world.events.projectileHit.subscribe(eventData => {
const blockHit = eventDatagetBlockHit()
if (!source.hasTag("gamer")) return;
if (!blockHit) return;
const { block } = blockHit
let power = block.getRedstonePower()
if (power >= 14) return;
// code here when player has tag and power is 14
{
source.runCommandAsync(`function getkey`)
}
})```
import { world } from "@minecraft/server"
world.events.projectileHit.subscribe(eventData => {
const {
source,
projectile,
blockHit
} = eventData
if (!source.hasTag("gamer")) return;
if (!blockHit) return;
const blockHit = eventData.getblockHit
let power = block.getRedstonePower()
if (power >= 14) return;
// code here when player has tag and power is 14
{
source.runCommandAsync(`function getkey`)
}
})```
u didnt removed block hit on top
import { world } from "@minecraft/server"
world.events.projectileHit.subscribe(eventData => {
const {
source,
projectile
} = eventData
if (!source.hasTag("gamer")) return;
const blockHit = eventData.getblockHit
if (!blockHit) return;
let power = block.getRedstonePower()
if (power >= 14) return;
// code here when player has tag and power is 14
{
source.runCommandAsync(`function getkey`)
}
})```
What about the first part
let a: ProjectileHitEvent;
......
OK. Thanks. I'm gonna test it out.
still doesn't work. Where can I find the changes. Could it be the source?
the error was just about block Hit
There are 2 errors in this [code](#1100963388173070358 message):
[36m<repl>.js[0m:[33m10[0m:[33m28[0m - [31merror[0m[30m TS2551: [0mProperty 'getblockHit' does not exist on type 'ProjectileHitEvent'. Did you mean 'getBlockHit'?
[7m10[0m const blockHit = eventData.getblockHit
[7m [0m [31m ~~~~~~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m15590[0m:[33m5[0m
[7m15590[0m getBlockHit(): BlockHitInformation | undefined;
[7m [0m [36m ~~~~~~~~~~~[0m
'getBlockHit' is declared here.
[36m<repl>.js[0m:[33m14[0m:[33m15[0m - [31merror[0m[30m TS2304: [0mCannot find name 'block'.
[7m14[0m let power = block.getRedstonePower()
[7m [0m [31m ~~~~~[0m
show errors
oh i forgot to ()
Should it be
eventData.getBlockHit()```
how did this end up to 300 comments