Stevertus / mcscript

A programming language for Minecraft Vanilla
https://mcscript.stevertus.com
MIT License
233 stars 16 forks source link

TypeError: Cannot Read Property 'type' of undefined #18

Closed KaiHicks closed 3 years ago

KaiHicks commented 4 years ago

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.

Thepyrocrafteur commented 4 years ago

Not sure but mcscript work with 1.13. Regarding to your summon, you're using 1.14 and maybe type:<biome> make compile job fail.

Stevertus commented 3 years ago

This error is fixed in the upcoming version. It was raised because calling modals inside of modals is not supported. Mcscript does not know how to read these keywords until the whole file was once analyzed, so I would have to do this recursivly. So the error is gone, but it just outputs spawnAllNPCs() now.