Cagealicous Posted August 14, 2019 Share Posted August 14, 2019 I have been attempting to make a certain prefab disappear when another mod is enabled. I have tried and tried and tried many things, but I am yet to be successful in this endeavor. This is the current one I am using. (I know that the mod doesn't exist. The name of the mod I am crossing this prefab with does work.) for k,v in ipairs(KnownModIndex:GetModsToLoad()) do local Mod = KnownModIndex:GetModInfo(v).name if Mod == ("INSERTMODNAMEHERE") then return else return Prefab("common/inventory/test", fn, assets) end end Whenever I try this out without the mod that I want the prefab to be not included, it shows up. Though, when I test it out with the mod, it still shows up. So, I gave up for the time being. If anyone could lend a helping hand, that would be appreciated. Link to comment Share on other sites More sharing options...
Ultroman Posted August 14, 2019 Share Posted August 14, 2019 Are you entirely sure that KnownModIndex:GetModInfo(v).name is the exact same name and casing as the string you are checking it against? Have you tried printing all the names (the "Mod" variable) it reads, to make absolutely sure? Link to comment Share on other sites More sharing options...
Cagealicous Posted August 14, 2019 Author Share Posted August 14, 2019 I'm not entirely sure what you mean. I may be a bit newer to coding, but I know some coding. (If that means anything.) Are you saying that if I checked if the "INSERTMODNAMEHERE" name is correct? I'm sorry if I do not understand. Link to comment Share on other sites More sharing options...
Ultroman Posted August 14, 2019 Share Posted August 14, 2019 Yes. Your whole thing here relies on "INSERTMODNAMEHERE" to be the exact same string as the .name of the mod data you're reading. If even a single char is the wrong casing, you will never get a hit. Try this, and then study the logs: for k,v in ipairs(KnownModIndex:GetModsToLoad()) do local Mod = KnownModIndex:GetModInfo(v).name print("Looking at mod: "..Mod) if Mod == ("INSERTMODNAMEHERE") then print("We got a hit!") return else print("Nope. Not it...") return Prefab("common/inventory/test", fn, assets) end end Link to comment Share on other sites More sharing options...
Cagealicous Posted August 15, 2019 Author Share Posted August 15, 2019 (edited) It still will not work. I've tried replacing the name of "INSERTMODNAMEHERE" with mods that I created. It's more than likely the code. I'm a bit at a loss here. Any other ideas? Edit: I've tried it out without the extra statement of "else". for k,v in ipairs(KnownModIndex:GetModsToLoad()) do local Mod = KnownModIndex:GetModInfo(v).name if Mod == ("INSERTMODNAMEHERE)") then return Prefab("common/inventory/test", fn, assets) end end This in fact does work, but the prefab will only show if the mod is enabled. I'm trying to get it to show up when it is disabled and when it is enabled to not show up. Edited August 15, 2019 by Cagealicous Link to comment Share on other sites More sharing options...
Ultroman Posted August 15, 2019 Share Posted August 15, 2019 Well, then just invert the condition. for k,v in ipairs(KnownModIndex:GetModsToLoad()) do local Mod = KnownModIndex:GetModInfo(v).name if Mod ~= ("INSERTMODNAMEHERE)") then return Prefab("common/inventory/test", fn, assets) end end But it make absolutely no sense that the code I gave doesn't work, if the code you showed does work. Zero. If I were you, I'd still put in those print statements to make sure it actually does what you think it does. Sometimes things look like they work when they actually don't. BTW, if you are very new to modding for DS/DST, I highly recommend looking at the newcomer post. It has a lot of great information for getting started, avoiding massive headaches, how to debug, example mods and great links. You should definitely take the Lua Crash Course, and preferably more tutorials. Lua is not completely like most programming languages. It's a scripting language posing as a programming language, and it has a deceptively simple structure that is almost so simple it's hard to understand when coming from e.g. Java, C++ or C#. Link to comment Share on other sites More sharing options...
Cagealicous Posted August 15, 2019 Author Share Posted August 15, 2019 (edited) It just isn't working. At this point, I really don't know what to do. Also, I'm not new to modding, only coding because my partner I worked with isn't available. So, I'm stumped at this point. I tried the first method and I tried inverting it. It still just shows up with the mod enabled. So, I don't know what to do now. Edited August 15, 2019 by Cagealicous Link to comment Share on other sites More sharing options...
Developer zarklord_klei Posted August 16, 2019 Developer Share Posted August 16, 2019 Your going about this wrong, you should be adding the prefab file to the PrefabFiles table in modmain if said mod isn't loaded. don't be mucking about with not returning the prefab from the file, just don't load the file in the first place. Link to comment Share on other sites More sharing options...
Cagealicous Posted August 16, 2019 Author Share Posted August 16, 2019 Well, I'm not entirely sure what you mean. I was just trying to make the prefab disappear when a certain mod was enabled. If that is what you are saying, then could you please demonstrate what you mean? Link to comment Share on other sites More sharing options...
Developer zarklord_klei Posted August 16, 2019 Developer Share Posted August 16, 2019 --in modmain.lua PrefabFiles = { --list of prefab file names } if not ModIsEnabled then --you need to find whatever check works here. table.insert(PrefabFiles, "prefab") --change prefab to be the name of the file your conditionally loading. end Link to comment Share on other sites More sharing options...
Cagealicous Posted August 17, 2019 Author Share Posted August 17, 2019 Alright. That didn't work as well. Since this is going nowhere, I'm going to move on for now. Thanks anyways. Link to comment Share on other sites More sharing options...
Ultroman Posted August 17, 2019 Share Posted August 17, 2019 Did you ever verify that the string you are trying to compare with actually matches the mod name you get from KnownModIndex:GetModInfo? Link to comment Share on other sites More sharing options...
Electroely Posted August 17, 2019 Share Posted August 17, 2019 On 8/15/2019 at 4:23 AM, Ultroman said: Well, then just invert the condition. for k,v in ipairs(KnownModIndex:GetModsToLoad()) do local Mod = KnownModIndex:GetModInfo(v).name if Mod ~= ("INSERTMODNAMEHERE)") then return Prefab("common/inventory/test", fn, assets) end end But it make absolutely no sense that the code I gave doesn't work, if the code you showed does work. Zero. If I were you, I'd still put in those print statements to make sure it actually does what you think it does. Sometimes things look like they work when they actually don't. Try thinking about exactly what the code does: for k, v in ipairs will loop through every element of the list of mods to load. Imagine the mod we DON'T want to load the prefab with is called "three". and imagine this is the mod list: - one - two - three - four Now, when the loop runs, it'll go through them one by one. It'll look at the first mod in the list (one) and it will run the conditional: one ~= three is true and thus we should return the prefab. It'll stop there because it already returned, despite the fact that there's 3 other elements in the list. Which means it ignores "three" because it's not the first on the list. And even if it is the first on the list, the loop won't return on the first iteration and will continue to the second. This code is basically guaranteed not to work, because this kind of situation requires +2 mods, and the code will only work properly if the single mod that's enabled is the one we're checking against. Here's a better solution: local found = false for k,v in ipairs(KnownModIndex:GetModsToLoad()) do local Mod = KnownModIndex:GetModInfo(v).name if Mod == "INSERTMODNAMEHERE" then found = true end end if not found then return Prefab("common/inventory/test", fn, assets) end Link to comment Share on other sites More sharing options...
Ultroman Posted August 18, 2019 Share Posted August 18, 2019 You're very right. Major oversight on my part. Sorry! This is why I recommended printing everything, to see exactly what was happening. 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