Jump to content

Creating new books for wickerbottom without overwriting files?


mouse

Recommended Posts

When I try to create the book recipes from modmain.lua and put them into STRINGS.TABS.BOOKS or RECIPETABS.BOOKS I get the error: "table index is nil". The books tab is created from within wickerbottom's prefab and I know overwriting prefabs is a big no-no but the only other thing I can do is create the books tab again from modmain.lua and that creates two book tabs, which is just silly and reflects poorly on my craftsmanship. I've already got everything else in my mod all lined up and ready to go but this has become a real thorn in my side.

Does anyone have any experience with this?

Link to comment
Share on other sites

From modmain.lua it is GLOBAL. before all global tables and variables like STRINGS and RECIPETABS

Correct and I have STRINGS = GLOBAL.STRINGS and RECIPETABS = GLOBAL.RECIPETABS at the top to make all of that easier.
Link to comment
Share on other sites

Could you upload what you have so far so I can take a look?

Sure but I think it would be easier to post the offending code rather than the entire mod so you wouldn't have to sort through it all.

STRINGS = GLOBAL.STRINGSRECIPETABS = GLOBAL.RECIPETABSRecipe = GLOBAL.RecipeIngredient = GLOBAL.IngredientTECH = GLOBAL.TECHlocal function hbooks(inst)    if GLOBAL.GetPlayer().prefab == "wickerbottom" then	STRINGS.NAMES.BOOK_HAPPY="Writing for Dummies"	STRINGS.RECIPE_DESC.BOOK_HAPPY = "Don't feel bad! Writer's block affects us all!"	local book_happy = Recipe("book_happy", {Ingredient("papyrus", 2), Ingredient("petals", 15)}, STRINGS.TABS.BOOKS, TECH.SCIENCE_TWO)	book_happy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_happy.xml")	book_happy.image = "book_happy.tex"	STRINGS.NAMES.BOOK_UNHAPPY="'The Room' Script"	STRINGS.RECIPE_DESC.BOOK_UNHAPPY = "A great evil lurks within these pages..."	local book_unhappy = Recipe("book_unhappy", {Ingredient("papyrus", 2), Ingredient("petals_evil", 7)}, STRINGS.TABS.BOOKS, TECH.SCIENCE_TWO)	book_unhappy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_unhappy.xml")	book_unhappy.image = "book_unhappy.tex"    endendAddPrefabPostInit("wickerbottom", hbooks)
Link to comment
Share on other sites

Ah, I see the problem - you're implying that 'The Room' actually had a script.

;P

 

Nice little joke there, though. x3

 

 

I'm afraid I can't offer any help with the problem, but I feel at this point I should mention that when I tried to add a custom crafting tab to my Link mod through Link's prefab, I couldn't get it to work.
Doing it through modmain did, but it causes the crafting tab sidebar to have an empty space where Link's craft tab would be, when playing as any other character with Link enabled.

Link to comment
Share on other sites

Ah, I see the problem - you're implying that 'The Room' actually had a script.

Bah, I've been bested! Well played.

I'm afraid I can't offer any help with the problem, but I feel at this point I should mention that when I tried to add a custom crafting tab to my Link mod through Link's prefab, I couldn't get it to work.

Doing it through modmain did, but it causes the crafting tab sidebar to have an empty space where Link's craft tab would be, when playing as any other character with Link enabled.

I don't want to tell you anything you may already know but the way it's done for wickerbottom's book tab is to create the tab within the character's prefab. These two lines seem to do the trick for her:

local booktab = {str = STRINGS.TABS.BOOKS, sort=999, icon = "tab_book.tex"}inst.components.builder:AddRecipeTab(booktab)
They also work from modmain.lua but it creates two book tabs which is not at all what I want. So I'm stuck with either overwritting her prefab, which creates the illusion of 1337 mod skills, or doing it from modmain, which is ugly but more technically sound. And again, I'm not trying to tell you anything you don't already know.
Link to comment
Share on other sites

  • Developer

Bah, I've been bested! Well played.

I don't want to tell you anything you may already know but the way it's done for wickerbottom's book tab is to create the tab within the character's prefab. These two lines seem to do the trick for her:

local booktab = {str = STRINGS.TABS.BOOKS, sort=999, icon = "tab_book.tex"}inst.components.builder:AddRecipeTab(booktab)
They also work from modmain.lua but it creates two book tabs which is not at all what I want. So I'm stuck with either overwritting her prefab, which creates the illusion of 1337 mod skills, or doing it from modmain, which is ugly but more technically sound. And again, I'm not trying to tell you anything you don't already know.

 

It's way easier for me if you post the mod and I can just run it and try stuff till it works :).

 

But I think you're really just talking about a timing issue so you might try adjusting the recipes using a callback added to 'AddSimPostInit' or 'AddGamePostInit'.  There's most likely something you can hook into which won't cause the issues you're talking about.  If you are ok with uploading your mod, I'll try some things and get back to you :).

Link to comment
Share on other sites

It's way easier for me if you post the mod and I can just run it and try stuff till it works :-).

 

But I think you're really just talking about a timing issue so you might try adjusting the recipes using a callback added to 'AddSimPostInit' or 'AddGamePostInit'.  There's most likely something you can hook into which won't cause the issues you're talking about.  If you are ok with uploading your mod, I'll try some things and get back to you :-).

Well sadly no. After making the necessary adjustments, AddSimPostInit and AddGamePostInit both result in the same error as AddPrefabPostInit. I don't doubt it's a timing thing though.

I've attached the mod zip file. The way I've packaged it, it's ready to show the error, which should happen after you load a wickerbottom save file. To see the way it's intended to work, move the included modified wickerbottom.lua file to /scripts/prefabs/ in the mod directory and comment out "AddPrefabPostInit("wickerbottom", hbooks)" in line 244 of modmain.lua.

Keep in mind, I haven't put much time into balancing the gameplay yet so it's not a finished product.

happy flowers.zip

Link to comment
Share on other sites

Bah, I've been bested! Well played.

I don't want to tell you anything you may already know but the way it's done for wickerbottom's book tab is to create the tab within the character's prefab. These two lines seem to do the trick for her:

local booktab = {str = STRINGS.TABS.BOOKS, sort=999, icon = "tab_book.tex"}inst.components.builder:AddRecipeTab(booktab)
They also work from modmain.lua but it creates two book tabs which is not at all what I want. So I'm stuck with either overwritting her prefab, which creates the illusion of 1337 mod skills, or doing it from modmain, which is ugly but more technically sound. And again, I'm not trying to tell you anything you don't already know.

 

Yeah, I copied the way Wickerbottom did it, and it just didn't work, for me... no clue why...

I'll have to take another stab at it, when I have time...

Link to comment
Share on other sites

  • Developer

Well sadly no. After making the necessary adjustments, AddSimPostInit and AddGamePostInit both result in the same error as AddPrefabPostInit. I don't doubt it's a timing thing though.

I've attached the mod zip file. The way I've packaged it, it's ready to show the error, which should happen after you load a wickerbottom save file. To see the way it's intended to work, move the included modified wickerbottom.lua file to /scripts/prefabs/ in the mod directory and comment out "AddPrefabPostInit("wickerbottom", hbooks)" in line 244 of modmain.lua.

Keep in mind, I haven't put much time into balancing the gameplay yet so it's not a finished product.

Not the prettiest solution but I believe this does what you want:

local function CreateRecipeTab(builder, tab)  for t in builder.custom_tabs do    if t.str == tab.str then      return t    end  end  builder:AddRecipeTab(tab)  return tabend local function hbooks(inst)  if GLOBAL.GetPlayer().prefab == "wickerbottom" then        local booktab = CreateRecipeTab(GLOBAL.GetPlayer().components.builder, {str = STRINGS.TABS.BOOKS, sort=999, icon = "tab_book.tex"})STRINGS.NAMES.BOOK_HAPPY="Writing for Dummies"STRINGS.RECIPE_DESC.BOOK_HAPPY = "Don't feel bad! Writer's block affects us all!"    local book_happy = Recipe("book_happy", {Ingredient("papyrus", 2), Ingredient("petals", 15)}, booktab, TECH.SCIENCE_TWO)    book_happy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_happy.xml")    book_happy.image = "book_happy.tex"    STRINGS.NAMES.BOOK_UNHAPPY="'The Room' Script"    STRINGS.RECIPE_DESC.BOOK_UNHAPPY = "A great evil lurks within these pages..."    local book_unhappy = Recipe("book_unhappy", {Ingredient("papyrus", 2), Ingredient("petals_evil", 7)}, booktab, TECH.SCIENCE_TWO)    book_unhappy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_unhappy.xml")    book_unhappy.image = "book_unhappy.tex"  endendAddPrefabPostInit("wickerbottom", hbooks)
Link to comment
Share on other sites

Not the prettiest solution but I believe this does what you want:

local function CreateRecipeTab(builder, tab)  for t in builder.custom_tabs do    if t.str == tab.str then      return t    end  end  builder:AddRecipeTab(tab)  return tabend local function hbooks(inst)  if GLOBAL.GetPlayer().prefab == "wickerbottom" then        local booktab = CreateRecipeTab(GLOBAL.GetPlayer().components.builder, {str = STRINGS.TABS.BOOKS, sort=999, icon = "tab_book.tex"})STRINGS.NAMES.BOOK_HAPPY="Writing for Dummies"STRINGS.RECIPE_DESC.BOOK_HAPPY = "Don't feel bad! Writer's block affects us all!"    local book_happy = Recipe("book_happy", {Ingredient("papyrus", 2), Ingredient("petals", 15)}, booktab, TECH.SCIENCE_TWO)    book_happy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_happy.xml")    book_happy.image = "book_happy.tex"    STRINGS.NAMES.BOOK_UNHAPPY="'The Room' Script"    STRINGS.RECIPE_DESC.BOOK_UNHAPPY = "A great evil lurks within these pages..."    local book_unhappy = Recipe("book_unhappy", {Ingredient("papyrus", 2), Ingredient("petals_evil", 7)}, booktab, TECH.SCIENCE_TWO)    book_unhappy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_unhappy.xml")    book_unhappy.image = "book_unhappy.tex"  endendAddPrefabPostInit("wickerbottom", hbooks)

Nope with that I get the error: "attempt to call a table value" in the line:

for t in builder.custom_tabs do
Thinking GLOBAL. might have been left out of the mix, I tried it again and it gave the error: "variable 'builder' is not declared" in the same line.
Link to comment
Share on other sites

  • Developer

Nope with that I get the error: "attempt to call a table value" in the line:

for t in builder.custom_tabs do
Thinking GLOBAL. might have been left out of the mix, I tried it again and it gave the error: "variable 'builder' is not declared" in the same line.

 

You are absolutely correct.  This here should work:

local function CreateRecipeTab(builder, tab)   for i, t in ipairs(builder.custom_tabs) do     if t.str == tab.str then    return t     end   end   builder:AddRecipeTab(tab)   return tabend  local function hbooks(inst)  if GLOBAL.GetPlayer().prefab == "wickerbottom" then        local booktab = CreateRecipeTab(GLOBAL.GetPlayer().components.builder, {str = STRINGS.TABS.BOOKS, sort=999, icon = "tab_book.tex"})STRINGS.NAMES.BOOK_HAPPY="Writing for Dummies"STRINGS.RECIPE_DESC.BOOK_HAPPY = "Don't feel bad! Writer's block affects us all!"    local book_happy = Recipe("book_happy", {Ingredient("papyrus", 2), Ingredient("petals", 15)}, booktab, TECH.SCIENCE_TWO)    book_happy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_happy.xml")    book_happy.image = "book_happy.tex"    STRINGS.NAMES.BOOK_UNHAPPY="'The Room' Script"    STRINGS.RECIPE_DESC.BOOK_UNHAPPY = "A great evil lurks within these pages..."    local book_unhappy = Recipe("book_unhappy", {Ingredient("papyrus", 2), Ingredient("petals_evil", 7)}, booktab, TECH.SCIENCE_TWO)    book_unhappy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_unhappy.xml")    book_unhappy.image = "book_unhappy.tex"  endendAddPrefabPostInit("wickerbottom", hbooks) 

post-283016-0-83029800-1381856212_thumb.

Link to comment
Share on other sites

You are absolutely correct.  This here should work:

local function CreateRecipeTab(builder, tab)   for i, t in ipairs(builder.custom_tabs) do     if t.str == tab.str then    return t     end   end   builder:AddRecipeTab(tab)   return tabend  local function hbooks(inst)  if GLOBAL.GetPlayer().prefab == "wickerbottom" then        local booktab = CreateRecipeTab(GLOBAL.GetPlayer().components.builder, {str = STRINGS.TABS.BOOKS, sort=999, icon = "tab_book.tex"})STRINGS.NAMES.BOOK_HAPPY="Writing for Dummies"STRINGS.RECIPE_DESC.BOOK_HAPPY = "Don't feel bad! Writer's block affects us all!"    local book_happy = Recipe("book_happy", {Ingredient("papyrus", 2), Ingredient("petals", 15)}, booktab, TECH.SCIENCE_TWO)    book_happy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_happy.xml")    book_happy.image = "book_happy.tex"    STRINGS.NAMES.BOOK_UNHAPPY="'The Room' Script"    STRINGS.RECIPE_DESC.BOOK_UNHAPPY = "A great evil lurks within these pages..."    local book_unhappy = Recipe("book_unhappy", {Ingredient("papyrus", 2), Ingredient("petals_evil", 7)}, booktab, TECH.SCIENCE_TWO)    book_unhappy.atlas = GLOBAL.resolvefilepath("images/inventoryimages/book_unhappy.xml")    book_unhappy.image = "book_unhappy.tex"  endendAddPrefabPostInit("wickerbottom", hbooks) 
attachicon.gifwicker_books.jpg

It seems to be working so far. I'll have to test it more later but so far so good. Thanks a lot! :grin:

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...