Trying to get a good understanding of how to make a mod

Ok, so I’ve been trying to follow voxel pirates great tutorial on how to add custom recipes to the carpenter. However I’m trying to do it different so that I don’t have to touch stonehearth.smod file. So far I’ve got Icon in crafting menu showing up and everything but as soon as I craft it my game crashes. I’m lead to believe that according to the .log file the paths for the promote_to_profession command is pointing to my mods directory rather than stonehearths. I’m hoping maybe someone could be kind enough to help me out. Here’s my talisman code:

{
“mixins”: “stonehearth:mixins:item_properties”,
“type”: “entity”,
“components”: {
“model_variants”: {
“default”: {
“models”: [
“file(/stonesword/entities/weapons/stone_sword/stone_sword.qb)”
]
}
},
“unit_info”: {
“name”: “Stone Sword”,
“description”: “Promotes a citizen into a Footman.”,
“icon” : “file(/stonesword/entities/weapons/stone_sword/stone_sword.png)”
},
“stonehearth:material” : {
“tags” : “wood melee_weapon crafted”
},
“stonehearth:commands” : {
“commands” : [
“file(/data/commands/promote_to_profession)”
]
},
“effect_list” : {
“effects” : [
“stonehearth:effects:talisman_glow”
]
},
“stonehearth:promotion_talisman”: {
“profession”: “stonehearth:professions:footman”
}
},
“entity_data” : {
“stonehearth:activity_name” : “promote_footman”
}
}

Also a small snippet from my log file which I believe is when the game crashed:

2014-Sep-24 11:15:18.796894 | server | 0 | lua.code | std::exception: ‘invalid file path ‘/stonesword/data/commands/promote_to_profession’.’

I’m not 100% whether or not that’s the culprit. This is my first mod so I’m just trying to get an understanding of how to create a custom weapon which basically acts the same as the wooden sword.

hey there @SpaceMonkey … I’ll point you to some blog posts, but they are likely no longer as valid as they once were…

http://stonehearth.net/2014/01/14/desktop-tuesday-a-peek-inside-the-modding-api/

http://stonehearth.net/2013/11/12/behind-the-scenes-with-bush-4/

other than that, paging @voxel_pirate! :smile:

Looks like you’re creating a mod that gives you a Stone Sword recipe which you can use to promote someone to a footman. Can you upload all of the files in your mod somewhere? It would help to have some more context.

Without the other files, I’d say your file paths are just wrong. Any time you prefix a path with “/”, the first item must be the mod it’s coming from. For example, “/stonehearth/…” would get you out of your mod and into the default Stonehearth stuff. If you don’t use a “/” at the beginning, then the path will be relative. So if you reference “a.json”, it’s going to look for “a.json” in the same folder as the current file.

Whatever file you have “/stonesword/data/commands/promote_to_profession” in is probably wrong. I’m not sure what to change it to but I can take a look if I can see the rest of your files.

Also, check out my Uncraftable mod (http://discourse.stonehearth.net/t/uncraftable-mod/7689) for a really easy example of creating a mod not using the stonehearth.smod file. It can also give you some examples of what you should do with your file paths.

Let me know if I can help any more. I’m just getting into this but I think most of it makes sense to me.

1 Like

Well…I’m stumped.

Here’s the link: Free File Hosting - Online Storage; Upload Mp3, Videos, Music. Backup Files

I appreciate the help, just forgive my poor art skillz lol first time messing with a voxel modeling program. Also I tried just copying the data files over to my mod just to see what would happend and the model didn’t even appear in game when it was on the ground. Not sure if I was referencing it wrong or if Quibicle Contruct was just outdated for stonehearth.

Edit: Ok, so i guess it’s not the model I’ve been able to get it to show in game but can’t promote anyone.

The file “entities\weapons\stone_sword\stone_sword.json” has a bunch of file paths in it that look like “file(stonesword/…)”. Those paths are wrong because they are relative and actually point at non-existent files. You just need to use something like “file(stone_sword.qb)” because the file you want is in the same directory. The same applies for the other .json files in that folder.

Ok, on to promoting.

First of all, the newest update changed the way promotions work in the API, so look in the default Stonehearth mod to see those changes. Looks like it affects the stone_sword_talisman.json file.

Second, assuming release 144, the promote command is set to “file(/data/commands/promote_to_profession)” which is actually exactly how the wooden sword is set up. Try changing it to “file(/stonehearth/data/commands/promote_to_profession)”. I think that will fix it.

Yea, I just noticed that the sword entities wasn’t point in the right directory from reading your previous post. I tried adding stonehearth to the front of the /data/ and I got this error:

2014-Sep-24 13:06:52.275329 | server | 0 | lua.code | std::exception: ‘invalid file path ‘/stonesword/stonehearth/data/commands/promote_to_profession’.’

So for some reason keeps wanting to look under stoneswords directory.

Close, make it:

"file(/stonehearth/data/commands/promote_to_profession)"

You put /stonesword as well which is invalid.

As a rule for file paths:

Putting a “/” at the very beginning makes it an ABSOLUTE path. That means you always need to use the FULL path to the file, starting with the name of the mod. For example “/stonehearth/entities/foo/bar” or “/stonesword/entities/foo/bar”

Leaving out the “/” at the very beginning makes it a RELATIVE path. That means that whatever you type in will be relative to where the current file is. So if you type “file(a.json)” in /stonesword/foo/bar.json, it’s going to look for “stonesword/foo/a.json”.

Make sense?

Hmm…maybe I’m misunderstanding you but that’s what I put and I got that error.

{
“mixins”: “stonehearth:mixins:item_properties”,
“type”: “entity”,
“components”: {
“model_variants”: {
“default”: {
“models”: [
“file(stone_sword.qb)”
]
}
},
“unit_info”: {
“name”: “Stone Sword”,
“description”: “Promotes a citizen into a Footman.”,
“icon” : “file(stone_sword.png)”
},
“stonehearth:material” : {
“tags” : “wood melee_weapon crafted”
},
“stonehearth:commands” : {
“commands” : [
“file(/stonehearth/data/commands/promote_to_profession)”
]
},
“effect_list” : {
“effects” : [
“stonehearth:effects:talisman_glow”
]
},
“stonehearth:promotion_talisman”: {
“profession”: “stonehearth:professions:footman”
}
},
“entity_data” : {
“stonehearth:activity_name” : “promote_footman”
}
}

Well I think that’s correct. Are you sure you’re loading up the most recent version of that file and that you’re staring a new world?

I looked around and found this post: Creating classes that talks about creating new professions. Since you’re re-using an existing one it should be simpler and @RepeatPan lists the exact same file path that you’re using for the promote_to_profession command.

I’ve got some work to do but keep trying and let me know if you get it to work. If not, I’ll try to look closer at it later tonight. You may also consider updating your game to the latest unstable build and using the new profession/job API.

This is not good. A “file(” chooses the path relative from the current map you are in.
So if you are in map mymod/profession/doctorX/
your current command looks for mymod/profession/doctorX/stonehearth/data/commands/promote_to_profession

While it should look for the stonehearth file.

So remove file( from it.

So “file(…)” means absolute and no “file(…)” means relative?

Stonehearth doesn’t use the presence/absence of the preceding forward slash to determine this?

file() is relative, no file is absolute. The forward slash in file() is “in this mod” to my knowledge, in absolute it means /mods/.

1 Like

Yeah, I think you’re basically right. I’ve been perusing the Stonehearth mod and I see that pattern.

  • file(…) roots you inside your mod. You can use / at the beginning to make it an absolute path starting with your mod root folder.
  • NO file(…) is just anything goes. Use a / at the beginning to root you inside the mods folder (start with /stonehearth or /mod_name in that case). Use no / at the beginning and it’s just a relative path.

@sdee Is this about right? What’s the benefit of the “file(…)” syntax other than being able to rename your mod without having to go fix all of your absolute paths? What’s the recommended way to use these?

1 Like

If I don’t misremember, you can use file(…) to abbreviate a little the path if it’s a json file, too.

For example, file(mixins/crafter_workbench) is short for file(mixins/crafter_workbench/crafter_workbench.json)

1 Like

Thank you, that worked. Only problem thought is that It won’t promote any of my workers. When I use the jofferson tool its telling me [alias] stonehearth:combat in red. Don’t really understand why its not working. ;\ I guess I may have to make a separate job for it.

1 Like

By my understanding, when file(foo.bar) is read in from json, the full path leading to foo.bar is actually constructed and stored in a string. This way, you can pass that string everywhere around your code (lua, html, etc) without worrying about relative paths.

For example, I’m working in trapper.json right now, and I want to specify an icon that will be useful to the character sheet. I can just write:

“icon” : “file(images/icon.png)”,

This produces the total path: stonehearth\jobs\trapper\images\icon.json, which is then assigned to the json node “icon” when the json file is read by the lua file that consumes it.

Since the .json file is then cached as a datastore inside trapper.lua, and since trapper.lua is referenced by the job component, I can then write something like

img {{bind-attr src = stonehearth:jobs.curr_controller.data.icon}}

in my html template and suddenly the icon appears on the screen. The UI doesn’t need to know anything about where the icon actually is, and neither does the .json file. If I move the trapper folder around (and we move folders around all the time) I don’t have to change anything becuase file() will read in the correct path when it is called.

3 Likes

Well, thanks to everyone’s help I did finally figure this out. I thought it would be fair for me to upload an example file of what I made. Basically my problem was, I was trying to add this as a talisman and well that didn’t quite work out. Here’s a copy of the mod I got working(Please note its for the unstable version currently on steam):

http://www.filedropper.com/stonesword

So hopefully that will help some people out. What I did here can also be applied to armors as well. Also whenever I exported my model I noticed that the Z-axis had to be exported as righthanded else the weapon would be equipped backwards.

1 Like