Coding Help Trying to change a schedule

Lenora Rose

Farmer
So I'm trying to write a Content Patcher Patch to change NPCs' schedules. I'm using Pierre as my test case because his vanilla schedule is VERY bare bones. The base idea is that there's something he starts doing gradually in year one, which has become a regular habit in year 2. (Nothing bad, I promise, since I mean for several other NPCs to do similar things.).

This is the code I have, aside from the schedule itself - which is long and which isn't coming up with errors, and which I am confident I did right (partly thanks to Visual Studio flagging things for me that I did oops on in that part.) I THOUGHT this was how to indicate a schedule that changes over time, but apparently I was wrong.:

{
"Changes": [
{
"Action": "EditData",
"Target": "Characters/schedules/Pierre",
"Entries": {
"rain": "GOTO spring",
"Fri": "700 SeedShop 10 20 0/830 SeedShop 4 17 2/1700 Saloon 16 20 0/2250 SeedShop 24 4 1 pierre_sleep",
etc.
},
"When": {
"Year": "1"
},
{
"rain": "GOTO Mon",
"etc
},
"When": {
"Year": "2"
}
}

]
}




Error log, if it helps, though I suspect someone whose coding experience isn't watching some tutorial videos and doing some C&P from better modders' code will be able to ID the problem from my base code. I guarantee it's a newbie error that makes me look dumb, but I'd rather look a fool and know what I *should* do and not just flail alone with my dignity intact. :)




Error loading patch 'StraySchedulesPierre > Include assets/Pierre/Schedules.json': an error occurred. StardewModdingAPI.Framework.Exceptions.SContentLoadException: Failed loading asset 'assets/Pierre/Schedules.json' from SMAPI\lenorarose.strayschedulespierre: an unexpected error occurred. ---> Newtonsoft.Json.JsonReaderException: Can't parse JSON file at C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Mods\[CP] Stray Schedules\assets\Pierre\Schedules.json. This doesn't seem to be valid JSON. Technical details: Invalid property identifier character: {. Path 'Changes[0].When', line 21, position 6. at StardewModdingAPI.Toolkit.Serialization.JsonHelper.ReadJsonFileIfExists[TModel](String fullPath, TModel& result) in E:\source\_Stardew\SMAPI\src\SMAPI.Toolkit\Serialization\JsonHelper.cs:line 80 at StardewModdingAPI.Framework.ContentManagers.ModContentManager.LoadDataFile[T](IAssetName assetName, FileInfo file) in E:\source\_Stardew\SMAPI\src\SMAPI\Framework\ContentManagers\ModContentManager.cs:line 193 at StardewModdingAPI.Framework.ContentManagers.ModContentManager.LoadExact[T](IAssetName assetName, Boolean useCache) in E:\source\_Stardew\SMAPI\src\SMAPI\Framework\ContentManagers\ModContentManager.cs:line 134 --- End of inner exception stack trace --- at StardewModdingAPI.Framework.ContentManagers.ModContentManager.LoadExact[T](IAssetName assetName, Boolean useCache) in E:\source\_Stardew\SMAPI\src\SMAPI\Framework\ContentManagers\ModContentManager.cs:line 146 at StardewModdingAPI.Framework.ModHelpers.ModContentHelper.Load[T](String relativePath) in E:\source\_Stardew\SMAPI\src\SMAPI\Framework\ModHelpers\ModContentHelper.cs:line 57 at ContentPatcher.Framework.Patches.IncludePatch.UpdateContext(IContext context) in E:\source\_Stardew\Mods.Pathoschild\ContentPatcher\Framework\Patches\IncludePatch.cs:line 105.
 

TildenJack

Tiller
Write it like this and it should work.

{
"Action": "EditData",
"Target": "Characters/schedules/Pierre",
"When": {"Year": "1"},
"Entries": {
"rain": "GOTO spring",
"Fri": "700 SeedShop 10 20 0/830 SeedShop 4 17 2/1700 Saloon 16 20 0/2250 SeedShop 24 4 1 pierre_sleep",
},
},

{
"Action": "EditData",
"Target": "Characters/schedules/Pierre",
"When": {"Year": "2"},
"Entries": {
"rain": "GOTO Mon",
},
},

etc...
 

Lenora Rose

Farmer
Write it like this and it should work.

{
"Action": "EditData",
"Target": "Characters/schedules/Pierre",
"When": {"Year": "1"},
"Entries": {
"rain": "GOTO spring",
"Fri": "700 SeedShop 10 20 0/830 SeedShop 4 17 2/1700 Saloon 16 20 0/2250 SeedShop 24 4 1 pierre_sleep",
},
},

{
"Action": "EditData",
"Target": "Characters/schedules/Pierre",
"When": {"Year": "2"},
"Entries": {
"rain": "GOTO Mon",
},
},

etc...
Thanks! i knew it had to be something straightforward but I wasn't finding an exact example to copy. I appreciate this.
 

Lenora Rose

Farmer
Write it like this and it should work.

{
"Action": "EditData",
"Target": "Characters/schedules/Pierre",
"When": {"Year": "1"},
"Entries": {
"rain": "GOTO spring",
"Fri": "700 SeedShop 10 20 0/830 SeedShop 4 17 2/1700 Saloon 16 20 0/2250 SeedShop 24 4 1 pierre_sleep",
},
},

{
"Action": "EditData",
"Target": "Characters/schedules/Pierre",
"When": {"Year": "2"},
"Entries": {
"rain": "GOTO Mon",
},
},

etc...
Some of the commas in your version turned out to be in the wrong places, but that's the sort of thing Visual Studio catches, so I got it to work.
I think.

Pierre didn't go where anticipated but it was also a Night Market day which might overwrite his schedule. About to try again now the Night Market is over.
 

Lenora Rose

Farmer
Some of the commas in your version turned out to be in the wrong places, but that's the sort of thing Visual Studio catches, so I got it to work.
I think.

Pierre didn't go where anticipated but it was also a Night Market day which might overwrite his schedule. About to try again now the Night Market is over.

Nope, he didn't move. Testing to progress another day....
 

Lenora Rose

Farmer
Try this one. Here he leaves his house at the start of each day in year 2 and stands by the benches below the saloon.
I can definitely check that. I think part of the issue is that the location I want him to go to is from a different mod. I added that as a dependency and checked its official name and coordinates via Debug, , but I was going to test whether the issue was not finding the location by having him walk to the bus and back.
 

Lenora Rose

Farmer
I can definitely check that. I think part of the issue is that the location I want him to go to is from a different mod. I added that as a dependency and checked its official name and coordinates via Debug, , but I was going to test whether the issue was not finding the location by having him walk to the bus and back.
Nope. Switched the schedule to just the bus stop. No movement. Compared every line of my mod with the one you provided, and found a possible missing tidbit in the content.json, but otherwise they matched up. Added that. Changed one capital letter, hoping that was the issue.

Pierre does not want to move.
 

Lenora Rose

Farmer
Now this is interesting - and a bit frustrating.

I swapped my mod with the one you listed... and it still didn't work. Something is missing.
 
Top