Jump to content

Trying to make a prefab not included with outside mod


Recommended Posts

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

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

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

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 by Cagealicous
Link to comment
Share on other sites

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

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 by Cagealicous
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...