stevertus / mcscript Goto Github PK
View Code? Open in Web Editor NEWA programming language for Minecraft Vanilla
Home Page: https://mcscript.stevertus.com
License: MIT License
A programming language for Minecraft Vanilla
Home Page: https://mcscript.stevertus.com
License: MIT License
if i try to run a modal inside an if statement, like this:
if ("condition") {
newModal()
}
it outputs
execute if condition run newModal()
instead of the modal code, it puts the modal call syntax
Hi,
the modaljs is a function that needs to return some minecraft commands. I think it would be more handy if you could return mcscript code :)
Let me lead of with I have found mcscript
very useful and fun to use. So, thank you for taking the time to make something like this.
Anyways, I know that Node should have a builtin Math
object so I tried to use some trig functions in to make something more extravagant. It didn't seem to work in the mcscript
for me so I was wondering if this could be added as an enhancement.
when given this text in a .mcscript file:
const TEST_CONST = 'this is a demonstration
of the issue with constants in MCScript'
/say $(TEST_CONST).repl(" the ", " an ")
the following is output in the mcfunction by the compiler:
say this is a demonstration;
of an issue with constants in MCScript
note the erroneous semicolon. it appears that the replace feature was created without multi-line constants in mind, but those are really useful for certain things so it'd be cool if this was fixed. thanks!
Hello. Is there any chance you could update this extension to include the new commands so that way VSCode doesn't yell at me thinking it's wrong?
Hello.
Is it possible to add flags like -build or something else to use in CI/CD jobs.
Using this flag should be like -fullErr
but exit the software wrongly to make CI/CD job fail when there are errors.
And maybe for CI/CD creating a flag -output <path>
for ya know.
You may think "Why CI/CD for such a small thing like this". Maybe one day it will be possible to execute unit test on mcfunction or maybe today there is a way to execute unit test on compiled mcfunction.
Maybe in future you will use the CI/CD flag to verify if code is optimized like @angular/cli does.
When comparing values against eachother, there's no way to test if two items are NOT EQUAL, other than converting the comparison check to a stringified version then negating it with an exclamation mark.
I'm proposing that there should be an unless
keyword which functions identically to the if
keyword, except instead of inserting if
it inserts unless
. Further, the contract between these two keywords should be so that if(!comparison)
=== unless(comparison)
and if(comparison)
=== unless(!comparison)
.
This keyword makes mcscript more consistent with Minecraft's /execute
command as well!
A use case for this is for checking inequality between two variables. This only works using one of two workarounds which make the pre- and post-compiled code both too large for a simple task:
// Setup
var selected @s = 1 // actually something more legitimate
var current @s = 0 // again, something more legitimate
// These don't work!
if(selected @s != current @s) {}
if(!'selected @s = current @s') {}
if(selected @s <> current @s) {}
// These are the workarounds
if(selected @s < current @s) {} // step 1
if(selected @s > current @s {} // step 2
// or
if(selected @s = current @s) {} else {}
I'd throw my hand up to help out, but 1) I've only stumbled upon this project and haven't fully looked at it, and 2) I'm already too deep in my rabbit hole of things which lead me here...
Love your work though! 🙌🐱🏍
Hi! I discovered a bug:
When writing an if/else statement that uses a boolean variable, the generator does not include the word "entity" inside the "unless" execute statement that was generated for the "else" statement, causing the datapack to not run. Here's an example:
My code:
Generated output:
Expected output:
Hi, just created my first datapack and I struggled much time with getting my datapack not loaded only because the namespace had an uppercase letter.
It would be nice if the command mcscript new ...
would convert the name into a minecraft conform name or at least give a warning :)
Any scripts that have a byte order mark accidentally added will not compile, with the following error message being produced:
[Error] Can't handle character: "" (0:0) in file .//data/mb/scripts/map/countdown.mcscript
.//data/mb/scripts/map/countdown.mcscript was not compiled!
BOM can be removed using something like the following:
.replace(/^\uFEFF|^\u00BB\u00BF/,"");
I can issue a PR doing so later.
There is a poly-fill trick for supporting arguments to functions using the new /data get storage [name] [path]
.
Format example:
mcscriptfunctions
|___ [function name]
|___ [meta data]
|___ [arguments]
|___ [0]
|___ [1]
|___ ...
|___ [N]
This will allow for real-time function calls if you create a macro that generates commands similar to the following code: (simulating using C#)
void callToFunction(string name, object[] args) {
string r = "/data modify storage MCScriptFunctions " + name + ".arguments set value [";
for(int i = 0; i < args.length; i++) r += args[i];
r += "]\n"
r += "/function " + name;
}
This could probably be optimized in many ways regarding to recursion etc (can be solved by storing arguments in temp variables), but this is the overall picture.
Many people uses VSCode compatible editor (VSCodium, VSCode-OSS,...), as the binary are free and open source.
However, these editor are not really allowed to use microsoft default market place.
It would be very useful to add this extension to open-vsx.org/
Thanks
When you add variables in the load file, it doesn't compile the mcscript/load function correctly and puts its content in the normal load function which then looks like this:
`function kitpvp:mcscript/load
say Loaded
scoreboard players set @s test 10
execute as @A run say test
"#" Extended from data/kitpvp/functions/load.mcscript
"#" to .//kitpvp/data/kitpvp/functions/load.mcfunction
kitpvp/data/kitpvp/functions/mcscript/load
"#" please do not touch this file!
"#" it is used by the compiler!
scoreboard objectives add test dummy`
(the quotes around the # are put in by me so github doesnt mess with them)
and thereby it doesnt load any of these files.
Hi there!
I was thinking about writing something similar to this when I stumbled upon this project. I have to admit that I haven't really looked into in very deeply yet, but there was one question that immediately sprung to my mind:
Why did you choose to use Node.js instead of something more native to the ecosystem like Java (or possibly Kotlin)?
Opinions about the design of these particular language's aside, I'd think that creating a compiler in Java/Kotlin would be easier due to the strongly-typed nature (although this could of course be circumvented by using something like Typescript).
It's also 'native' to the minecraft ecosystem, given that the java edition is written in it (mindblowing isn't it?) and so are basically all (forge) mods.
Everyone that has minecraft installed also has the included JVM, so installing an extra runtime wouldn't be necessary.
I'm not trying to 'judge' you or anything, I'm honestly just curious.
I might try to contribute to this project in the future (if I find the time for it), so if there's anything you "need help with" I'll be happy to hear it 😄
While using VSC (with Minecraft Script
extension) commands written starting with /
do not have tooltip.
Probable fix: "borrow" some code from language-mcfunction
extension.
Also, please, make "event detector" (in load scoreboard objectives add {name} {event_type}
and in tick (or "main" as it called) execute as @a[scores={{name}=1..}] ...
and scoreboard players set @a {name} 0
Hey,
I absolutely love what you are doing with this, however, in grouping... there is a slight bug when trying to group store. I'm not finding a way to do something like
execute store result bossbar <name> value run scoreboard players get <selector> <objective>
I have tried to do
store('result bossbar <selector> value') {
scoreboard players get <selector> <objective>
}
However, it complies to
execute store(result bossbar <selector> value) run scoreboard players get <selector> <objective>
Unless I'm reading the documentation wrong, I believe that this is a bug. If not then sorry 😃
Thanks... and Keep up the great work,
Alex (alvin8t)
The following creates invalid output:
if ('score X Y matches 1') {
# Comment
say hi
}
The output is:
execute if score X Y matches 1 run # Comment
execute if score X Y matches 1 run say hi
Slash comments (//
) must be used instead.
What should happen is that the hash comment is just placed before the following command, like:
# Comment
execute if score X Y matches 1 run say hi
Variables are always declared as type "dummy". To allow the /trigger
command they must be declared as type "trigger"
Currently, declaring a var yields this:
var myVariable
==> /scoreboard objectives add myVariable dummy
I would like to be able to declare a trigger somehow. Either with a new keyword similar to "var" or an argument after the variable name:
var myVariable trigger
==> /scoreboard objectives add myVariable trigger
Hi. First off, i'm loving using mcscript! I am making a continuous game, which is spread out between multiple dimensions. Your compiler doesn't seem to like:
in('minecraft:minigames'){
run: say hi
}
so therefore I am having to work around it by doing:
as('@s in minecraft:minigames'){
run: say hi
}
The workaround isn't that annoying, it's not a big deal. My issue is, I am now having to use that extra as @s
where it is not needed.
Once again, thanks for providing such an amazing resource. It takes a lot of the repeating out and is generally really clean and easy to use.
Retro
The compiler assumes that an else
statement after if(!condition1 && !condition2)
is if(condition1 && condition2)
, when in reality it should be if(condition1 || condition2)
(aka if(!(!condition1 && !condition2))
which mcscript doesn't seem to support)
Example, should kill a dropped item if it has a block of gold 1 or 2 blocks below it and set the block at it's current position to a red banner otherwise, but it will instead kill it only when both blocks are blocks of gold:
asat(@e[type=minecraft:item]) {
if(!'block ~ ~-1 ~ minecraft:gold_block' && !'block ~ ~-2 ~ minecraft:gold_block') {
/setblock ~ ~ ~ minecraft:red_banner
} else {
/kill @s
}
}
When I use mcscript watch in the terminal, after defining a variable, it tells me that the variable has already been defined, when it’s the only line of code. However, when I use mcscript compile instead, it gives me no error.
Apart from that, when I put a Boolean into an if,it doesn’t parse well the command. But when I negate it, it works correctly, here’s an example:
Mcscript code:
If(ready @s){ Run say hi }
The output is:
Execute if ready run say hi
when it should be:
Execute if entity @s[tag=ready] run say hi
. But when negated, it gives the proper unless statement
I think it is meant to be http://stevertus.**com**/mcscript and not .ga
with .ga I get redirected to somewhere - else...
and not your website.
That is the minor bug. If this bug is fixed, the datapacks generated will be compatible up to minecraft 1.16.1 and onwards. But I have a small suggestion on something you can add to the "mcscript new" command regarding pack.mcmeta. Currently, every datapack is generated with a pack.mcmeta file with the "pack_format" key set to 1. The "pack_format" key tells minecraft what version the datapack was made for. Minecraft can and will load datapacks for older versions, but never newer versions.
The "pack_format" ids according to the wiki are as follows:
1 for minecraft 1.6 - 1.8
2 for 1.9 and 1.10
3 for 1.11 and 1.12
4 for 1.13 and 1.14
5 for 1.15 and 1.16
My suggestion is that you can add an optional argument to mcscript new. The syntax could be something like this:
"mcscript new -version:"
Original: Hectoris919
#4922
Using #file:
with content above it creates erroneous files that are placed in the root data pack directory.
Example:
#Header#
#file: ./x
/say hi
#file: ./y
/say hello
When compiled, the following occurs:
Generated #Header#.mcfunction
Generated .//data/DATAPACK/functions/x.mcfunction
Generated .//data/DATAPACK/functions/y.mcfunction
The content above the first #file
should either be:
A.mcscript
it should be compiled to .//data/DATAPACK/functions/A.mcfunction
, not ./#Header#.mcfunction
.currently, im struggling doing this:
asat(@a) {
var slimeKilled @s = 0
if ('entity @s[nbt={SelectedItem:{id:"minecraft:stick",Count:1b}}]') {
raycast(10, "air", entity @e[type=slime]) {
/kill @s
slimeKilled @s = 1 // @s points to the raycasted entity instead of parent entity (player)
}
if (slimeKilled @s == 1) {
/say Oops, you killed a slime (accedentally).
slimeKilled @s = 0
}
}
}
is there a way of getting the player?
I was writing code in the main.mcscript file and was getting this:
Read 5 Files and compiled successfully
Read 5 Files and compiled successfully
Generated .//game/data/game/functions/mcscript/load.mcfunction
Generated .//mechanics/data/mechanics/functions/mcscript/load.mcfunction
Generated .//game/data/game/functions/load.mcfunction
Generated .//mechanics/data/mechanics/functions/load.mcfunction
Generated .//mechanics/data/mechanics/functions/main.mcfunction
Generated .//game/data/game/functions/mcscript/load.mcfunction
Generated .//mechanics/data/mechanics/functions/mcscript/load.mcfunction
Generated .//mechanics/data/mechanics/functions/load.mcfunction
Generated .//game/data/game/functions/load.mcfunction
Generated .//mechanics/data/mechanics/functions/main.mcfunction
TypeError: Cannot read property 'type' of undefined
at js (C:\Users\[Name]\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:30:21)
at js_modal (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:505:26)
at js (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:37:36)
at Array.map (<anonymous>)
at js_prog (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:370:30)
at js (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:64:35)
at generate (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:20:15)
at Object.parseCode (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:652:16)
at C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\index.js:109:21
at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
TypeError: Cannot read property 'type' of undefined
at js (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:30:21)
at js_modal (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:505:26)
at js (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:37:36)
at Array.map (<anonymous>)
at js_prog (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:370:30)
at js (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:64:35)
at generate (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:20:15)
at Object.parseCode (C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\generator.js:652:16)
at C:\Users\username\AppData\Roaming\npm\node_modules\mcscript\lib\index.js:109:21
at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
Here is the code:
#file: ./main
// here goes your main content
// executes 20 times a second
////ClassEnforcement
modal enforceClasses() {
//This will enforce the use of the proper items determined by the user's class
//all this stuff does not apply to people in creative mode
//give slowness to all non-swordsmen holding a sword
/effect give @a[gamemode=!creative, tag=!g_class_swordsman, nbt={SelectedItem:{id:"minecraft:diamond_sword"}}] minecraft:slowness 1 1
/effect give @a[gamemode=!creative, tag=!g_class_swordsman, nbt={SelectedItem:{id:"minecraft:iron_sword"}}] minecraft:slowness 1 1
//give slowness to all non-archers holding a bow/crossbow
/effect give @a[gamemode=!creative, tag=!g_class_archer,nbt={SelectedItem:{id:"minecraft:bow"}}] minecraft:slowness 1 1
/effect give @a[gamemode=!creative, tag=!g_class_archer,nbt={SelectedItem:{id:"minecraft:crossbow"}}] minecraft:slowness 1 1
}
////Spawning
modal spawnUppruniBowyer() {
if(!'entity @e[name="Bowyer"]') {
/summon villager 0 0 0 {VillagerData:{profession:fletcher,level:99,type:taiga},Invulnerable:1,PersistenceRequired:1,Attributes: [{Name: "generic.movementSpeed",Base: 0},{Name: "generic.knockbackResistance",Base: 1.0}],CustomName:"\"Bowyer\"",Offers:{Recipes:[{buy:{id:emerald,Count:6},sell:{id:bow,Count:1},maxUses:9999999},{buy:{id:emerald,Count:10},sell:{id:bow,Count:1,tag:{Enchantments:[{id:power,lvl:1}]}},maxUses:9999999},{buy:{id:emerald,Count:1},sell:{id:crossbow,Count:1},maxUses:9999999}]}}
}
}
modal spawnNPCsInUppruni() {
spawnUppruniBowyer();
}
modal spawnAllNPCs() {
spawnNPCsInUppruni()
}
enforceClasses()
spawnAllNPCs()
And this is the .mcfunction that is being generated:
#######
# Compiled from data/game/functions/main.mcscript
# to .//game/data/game/functions/main.mcfunction
#
# Generated by Minecraft Script for 1.13
######
effect give @a[gamemode=!creative, tag=!g_class_swordsman, nbt={SelectedItem:{id:"minecraft:diamond_sword"}}] minecraft:slowness 1 1
effect give @a[gamemode=!creative, tag=!g_class_swordsman, nbt={SelectedItem:{id:"minecraft:iron_sword"}}] minecraft:slowness 1 1
effect give @a[gamemode=!creative, tag=!g_class_archer,nbt={SelectedItem:{id:"minecraft:bow"}}] minecraft:slowness 1 1
effect give @a[gamemode=!creative, tag=!g_class_archer,nbt={SelectedItem:{id:"minecraft:crossbow"}}] minecraft:slowness 1 1
I am at a loss for what might be wrong.
When I type:
var minx = 5
it compiles successfully, but when I type:
var minx = -5
this happens:
Error: Unexpected token: {"type":"num","value":5} (9:13) in file .//claims/data/claims/scripts/load.mcscript
at Object.croak (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\lexer.js:85:12)
at unexpected (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:58:11)
at C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:629:7
at maybe_call (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:570:12)
at parse_atom (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:577:12)
at maybe_binary (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:92:35)
at parse_var (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:419:18)
at C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:588:49
at maybe_call (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:570:12)
at parse_atom (C:\Users\User\AppData\Roaming\npm\node_modules\mcscript\lib\parser.js:577:12)
Edit: There is a workaround:
var minx = 0
minx -= 5
I'm planning on using this with another project. While not strictly required for normal operation of this project, it would make things easier for people looking to use this project in buildscripts.
Minecraft has support for a built in function called schedule that combined with code blocks could create very basic asynchronous code. Supporting the schedule command as a language feature rather than a command is mostly just syntactic sugar:
after (<time>d|s|t, replace) {
/say hi!
}
The replace field is optional and could be a different keyword or identifier. By default though, this should compile to append rather than replace.
This would be similar to putting your code in other function and calling /schedule d|s|t , but it looks a lot nicer when you have your code in one file.
Follow this code:
var constants
if(constants c1 > 0){
/say hi
}
will compiled to
scoreboard objectives add constants dummy
execute if score c1 c1 matches 1.. run say hi
and I expected this
scoreboard objectives add constants dummy
execute if score c1 constants matches 1.. run say hi
I think this need fix.
I want to declare a bool (tag) as this
bool <name> <entity>
so I can use it like
if (<name> <entity>)
but currently I need to assignt the bool to define it like this
bool <name> <entity> = <false | true>
which doesnt work for me as it is set by other functions
This isn’t an issue but on this site feature requests are usually put in Issues.
I haven’t used this yet but it looks really good. Maybe you could add strings in variables for snapshots by using the new NBT manipulation tags to store them?
Also your website seems to be down. It’s reporting a 502 error.
Edit: Actually I don't think this is easily possible
Title says it all, I just wasn't sure where else to ask this.
I wanted to to a simple asat(@e[type=marker,tag=test]){} but on compiling, i got the error
Error: Unexpected token: {"type":"kw","value":"asat"}
What should I do? I reinstalled and updated the (node) module but the error still is there...
the code that's causing the problem is:
#file: ./main
asat(@e[type=marker,tag=mei,tag=!setup]) {
/setblock ~ ~ ~ red_shulker_box
/tag @s add mes.setup
}
In basic vanilla functions, random numbers are annoying to generate. This would be a very useful tool in making the process simpler.
Hi everyone!
When I run mcscript new
and name of my project, I have a lot of errors and my antivirus (Avast) is blocking your files (.html files in node package). And my browser is telling me, that some parts of your website (dManager and mcscript) are dangerous (mcscript website is blocked by Avast too).
Is it really dangerous or it should be an error in my antivirus?
Thanks!
EDIT: When I deleted docs folder, everything worked fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.