Silentdarkness1 Posted April 23, 2017 Share Posted April 23, 2017 I have an idea for a mod I could make, regarding speech files(the examine quotes, and such), and i'm wondering. Would the game complain or crash if I had a mod that provided speech quotes for mods that weren't loaded? Or would it just ignore them in that case? Link to comment Share on other sites More sharing options...
Serpens Posted April 23, 2017 Share Posted April 23, 2017 3 hours ago, Silentdarkness1 said: I have an idea for a mod I could make, regarding speech files(the examine quotes, and such), and i'm wondering. Would the game complain or crash if I had a mod that provided speech quotes for mods that weren't loaded? Or would it just ignore them in that case? strings are usually only a table with entries. It depends on how the structure of the strings from the mod is. Assume a mod strings table looks like this: STRINGS = {} STRINGS.WILSON = {} STRINGS.WILSON.EXAMINE = {} STRINGS.WILSON.EXAMINE.butterfly = "nice butterfly" Now you can easily change the string by doing: STRINGS.WILSON.EXAMINE.butterfly = "stupid butterfly" But if the mod is not loaded, it could be that STRINGS.WILSON or STRINGS.WILSON.EXAMINE does not exist (is "nil"). And doing "nil.butterfly" will crash. So you should check first, if they are nil or not. So when changing the butterfly string, you should do: if STRINGS.WILSON and STRINGS.WILSON.EXAMINE then STRINGS.WILSON.EXAMINE.butterfly = "stupid butterfly" end Then it won't crash, when they do not exist. Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted April 23, 2017 Author Share Posted April 23, 2017 @Serpens I'm sorry, i'm having just a little trouble understanding. I would be using this format: STRINGS.CHARACTERS.GENERIC.DESCRIBE.etc etc. Would this crash, if the requisite mod wasn't loaded alongside it? Link to comment Share on other sites More sharing options...
Serpens Posted April 23, 2017 Share Posted April 23, 2017 (edited) 5 minutes ago, Silentdarkness1 said: @Serpens I'm sorry, i'm having just a little trouble understanding. I would be using this format: STRINGS.CHARACTERS.GENERIC.DESCRIBE.etc etc. Would this crash, if the requisite mod wasn't loaded alongside it? it depends on what the mod strings look like. Do you have examples? So STRINGS.CHARACTERS.GENERIC.DESCRIBE is already in the game and won't crash. But a mod could add something like this: STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYMOD = {} STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYMOD.mymodnewthing = "this and that" When you now try to change "mymodnewthing", it will crash if mod is not loaded. Instead you have to check first if STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYMOD is not nil. Edited April 23, 2017 by Serpens Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted April 23, 2017 Author Share Posted April 23, 2017 @Serpens Ok, so it would crash, and I would indeed have to run a check on the mod. How exactly would I go about doing a check? Link to comment Share on other sites More sharing options...
Serpens Posted April 23, 2017 Share Posted April 23, 2017 (edited) 28 minutes ago, Silentdarkness1 said: @Serpens Ok, so it would crash, and I would indeed have to run a check on the mod. How exactly would I go about doing a check? everything would be muuuch more easier to understand for you, if you would have an example. All you need is what I wrote above. A check if the table is nil or not. This is one additional line per table to mod is introducing. If the mod does not introduce new tables, but only strings, you don't need them at all. So lets use the example character mod "Medic". This mod is only using existing string tables. It does nowhere "...= {}" with STRINGS. Therefore you can change strings without problem and without crash. (of course your mod must load after the other mod) At the moment I don't know an example mod, where a new table is introduced. You have to see it yourself, while making your mod. Like Ialready wrote above if you see something like this: STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYMOD = {} (a new table is created) then it will crash, if your line is only: STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYMOD.mymodnewthing = "this" To prevent crash in this case your code should be: if STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYMOD then STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYMOD.mymodnewthing = "this" end Edited April 23, 2017 by Serpens added code tags Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted April 23, 2017 Author Share Posted April 23, 2017 Ok, so as an example... if STRINGS.CHARACTERS.GENERIC.DESCRIBE.DELUXEPOT then STRINGS.CHARACTERS.GENERIC.DESCRIBE.DELUXEPOT.EMPTY = [[It's an investment in cuisine.]] end Like that? Link to comment Share on other sites More sharing options...
Serpens Posted April 23, 2017 Share Posted April 23, 2017 (edited) ... it is really hard to explain something like behaviour of tables to someone who has absolutely no experience with that I wrote everything you need to know in the last post and unfortunately I have no clue how to make it more clear. I think the best for you would be the following answer: No, there will be no crashes (which should be true in 99% of the cases) But if you experience a crash, come back here and I will tell you on that example, how to prevent the crash. PS: in your example code, why there is [[ ? Edited April 23, 2017 by Serpens Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted April 23, 2017 Author Share Posted April 23, 2017 Just now, Serpens said: PS: in your example code, why there is [[ ? Well, in a previous version of a speech mod template I have, the author used [[]] instead of quotations and commas. And it worked just fine. Link to comment Share on other sites More sharing options...
Serpens Posted April 23, 2017 Share Posted April 23, 2017 1 minute ago, Silentdarkness1 said: Well, in a previous version of a speech mod template I have, the author used [[]] instead of quotations and commas. And it worked just fine. ah okay, did not know about that, thx Link to comment Share on other sites More sharing options...
Lumina Posted April 23, 2017 Share Posted April 23, 2017 There is a line to test if a mod is enabled. Maybe it's what you want ? you need to know the workshop number of the mod as far as i know. At the moment i don't remember the line, so let me know if it's what you need and i'll search. Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted April 23, 2017 Author Share Posted April 23, 2017 (edited) Yes, a friend of mine told me. TheModIndex, something or other? EDIT: Got it now. KnownModIndex:IsModLoaded("") Edited April 23, 2017 by Silentdarkness1 Link to comment Share on other sites More sharing options...
Lumina Posted April 23, 2017 Share Posted April 23, 2017 if GLOBAL.KnownModIndex:IsModEnabled("workshop-434383046") then STRINGS.RECIPE_DESC.BROWN_MUSHROOM = "Mushroom. More mushroom." local brown_mushroom = AddRecipe("brown_mushroom", {Ingredient("turf_marsh", 1), Ingredient("brown_cap", 1, "images/inventoryimages/brown_cap.xml"), Ingredient("livinglog", 1), Ingredient("waterballoon", 1) }, RECIPETABS.FARM, TECH.SCIENCE_TWO, "blue_mushroom_placer", 0.8, nil, nil, nil, "images/inventoryimages/brown_cap.xml", "brown_cap.tex" ) end I used this on an old mod, it worked fine, but it's old so i don't know if it's still the case.Also don't forget GLOBAL. before STRINGS Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted April 23, 2017 Author Share Posted April 23, 2017 Thanks for pointing out the GLOBAL. That'll be coming in handy real soon. Ok, I think I understand now. Link to comment Share on other sites More sharing options...
Serpens Posted April 23, 2017 Share Posted April 23, 2017 (edited) yes you can use that function to test if a mod is active, but you really don't need it in your case, never. (as long as you are only changing strings) Edited April 23, 2017 by Serpens Link to comment Share on other sites More sharing options...
Lumina Posted April 23, 2017 Share Posted April 23, 2017 (edited) Depend of what you want to do, no ? Let say i have a custom character and i want it to have a custom description for the food added by beefalo milk mod Isn't easier to do if GLOBAL.KnownModIndex:IsModEnabled("workshop-whateverthenumberis") then GLOBAL.STRINGS.CHARACTERS.MYCHARACTER.DESCRIBE.PREFAB1 = "Blabla." GLOBAL.STRINGS.CHARACTERS.MYCHARACTER.DESCRIBE.PREFAB2 = "Blabla." GLOBAL.STRINGS.CHARACTERS.MYCHARACTER.DESCRIBE.PREFAB3 = "Blabla." GLOBAL.STRINGS.CHARACTERS.MYCHARACTER.DESCRIBE.PREFAB4 = "Blabla." end ? Or do i misunderstood how your code is supposed to work ? Edited April 23, 2017 by Lumina Link to comment Share on other sites More sharing options...
Silentdarkness1 Posted April 23, 2017 Author Share Posted April 23, 2017 @Lumina Thanks. I think you have it down right. This probably is the easiest way to do what I want to do. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now