4

[Help] load.json causing problems

Chickblock 3/17/22 6:28 pm
1.3k
3/18/2022 7:18 am
Could someone help me I am thoroughly confused. So I have a command in my datapack that is executed from load.json function the command is: execute unless entity @e[type=armor_stand,name=team_lives,scores={first_time_setup=1}] run summon armor_stand 0 255 0 {Tags:["armor_stand_life"],Invisible:4b,Invulnerable:4b,PersistenceRequired:4b,NoBasePlate:4b,NoGravity:4b,CustomName:'{"text":"team_lives"}',DisabledSlots:4444959} Basically what this will do is unless first_time_setup (the score) = 1 then it will summon a new armor stand. first_time_setup is automatically set to 1 with another function and I checked there is an armor stand in the world that has first_time_setup=1 which means that is should not summon a new one and when I run it via a command block nothing happens like it should. But for some reason when it's in the datapack despite me having ran it via command block and it working as intended it summons a new armor stand (but it shouldn't). I'm doing this in single player and I've noticed that it only happens when I leave/re-join a worlds so it has to be coming from the load.json function since when I disable/re-enable the datapack nothing breaks. This leads me to believe that here may be a time between load.json loading and running the command then the the world fully loading (with the armor stand in it) So it might be that the armor stand isn't loaded at the time it checks. Either way any ideas?
Posted by
Chickblock
Level 19 : Journeyman Network
0

  Have something to say?

JoinSign in

4

Kefaku
03/18/2022 2:04 am
Level 45 : Master Nerd
history
You could also just put the command in a different function and schedule it. For Example:

load.mcfunction:
schedule function <namespace>:load_delayed 40t append
load_delayed.mcfunction
execute unless entity @e[type=armor_stand,name=team_lives,scores={first_time_setup=1}] run summon armor_stand 0 255 0 {Tags:["armor_stand_life"],Invisible:4b,Invulnerable:4b,PersistenceRequired:4b,NoBasePlate:4b,NoGravity:4b,CustomName:'{"text":"team_lives"}',DisabledSlots:4444959}
That would execute load_delayed.mcfunction (your previous load.mcfuntion) 40t (=2s) after the world has loaded, when the armorstand already should have loaded. This for sure is not the best method to do it, because a slow computer might need a longer delay and a fast computer would be okay with a shorter delay, but it is the easiest solution I could think of.
Also as toothgenie already said, you should use markers instead of armorstands in 1.17+.
2
toothgenie
03/17/2022 8:48 pm
Level 16 : Journeyman Crafter
Have you set the armor stand's score?

What's probably happening is that when you load up a new world, the load.json functions execute before you load in. This is normally fine, but since you're depending on an entity's score, if the entity is not loaded the test will pass. By the looks of what you're saying, this is a global variable for the pack, not the entity, and so to fix this you should set a playername to have first_time_setup = 1. For example, you could do (in the function that sets first_time_setup to 1):scoreboard players set FredBloggs first_time_setup 1Then, in your function here, simply change it to accommodate for the change:execute unless score FredBloggs first_time_setup matches 1 run summon armor_stand 0 255 0 {Tags:["armor_stand_life"],Invisible:4b,Invulnerable:4b,PersistenceRequired:4b,NoBasePlate:4b,NoGravity:4b,CustomName:'{"text":"team_lives"}',DisabledSlots:4444959} This will mean that even if the armor stand is not loaded in, the test will fail and not create another armor stand.
It's worth noting though that you should use either a 2-character or 17+ character (though idk if you can) playername as otherwise someone with the username might be affected if you're using the scoreboard for something else. In this instance you probably don't have to, so just choose a playername that makes sense (i.e. not FredBloggs)

Also, assuming you're on 1.17+ consider using marker entities instead of invisible armor stands. They are much less laggy, and don't render client-side, and basically do the same thing minecraft.fandom.com/wiki/Marker
4
Chickblock
03/17/2022 9:21 pm
Level 19 : Journeyman Network
history
Thank you so much I spend like 2 hours just trying to figure out why it wasn't working. I'm newer to datapack creation so I wasn't aware that load.json was trigger before the actual world was loaded in. I'll try this and see how it works.
[​Edit] Just did a little bit of testing and everything seems to work properly
3
toothgenie
03/18/2022 7:18 am
Level 16 : Journeyman Crafter
Amazing! That always catches me out in dev, when I have an entity that I'm dependant on and there are loading issues, so be on the lookout for it!
1

Welcome