Jump to content

Question...


Nycidian

Recommended Posts

it should be there in the files unless of course, you mean something else. If so disregard this post

 

I am building a submodule that will be called from the main mod but as it may be called from different mods and each call might be different versions of my submod I need to be able to differentiate the submods being called the way I do that now is I have to have two lines of code placed in the modmain.lua

ModName = "<modname>"modimport("amanager/start.lua") 

The ModName variable is what ends up differentiating the different submodule instances, however I would like to do away with that variable making it one line. If there was a way in lua to see what directory path a file was in I could do this, that is what I am asking.

Link to comment
Share on other sites

  • Developer

I am building a submodule that will be called from the main mod but as it may be called from different mods and each call might be different versions of my submod I need to be able to differentiate the submods being called the way I do that now is I have to have two lines of code placed in the modmain.lua

ModName = "<modname>"modimport("amanager/start.lua") 

The ModName variable is what ends up differentiating the different submodule instances, however I would like to do away with that variable making it one line. If there was a way in lua to see what directory path a file was in I could do this, that is what I am asking.

I think you can cheat it by using the debug functions.  I can print the path to the lua file by using the following code:

 

print(GLOBAL.debug.getinfo(1).source)

 

Which prints:

@C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/workshop-186053703/modmain.lua

Link to comment
Share on other sites

I think you can cheat it by using the debug functions.  I can print the path to the lua file by using the following code:

print(GLOBAL.debug.getinfo(1).source)

Which prints:

@C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/workshop-186053703/modmain.lua

YAY! that is what I am looking for I can use string functions I believe to get what I want out of that

 

 

So I don't have to post another topic for a related question for the same mod hers another question.

 

I'm trying to make sure the the correct version of a component is loaded and I can differentiate between each version but my problem is to load the component universally I have to use...

AddPrefabPostInit("world", function(inst)	print("                   step 2", ModNameLoc)		if bestVersion then		    GLOBAL.assert( GLOBAL.GetPlayer() == nil )		    local player_prefab = GLOBAL.SaveGameIndex:GetSlotCharacter()		 		    -- Unfortunately, we can't add new postinits by now. So we have to do		    -- it the hard way...		 		    GLOBAL.TheSim:LoadPrefabs( {player_prefab} )		    local oldfn = GLOBAL.Prefabs[player_prefab].fn		    GLOBAL.Prefabs[player_prefab].fn = function()		        local inst = oldfn()		 		        -- Add components here.		        inst:AddComponent("amanager")		        GetPlayer().components.amanager:Populate(GLOBAL)		 		print("The "..ModNameLoc.." WAS instaled as AManager was either not installed or this is the highest version")		        return inst		    end	    end    end)

But the if function doesn't really work as the function that tests for it has to be in siminit so I tried overwriting the component only on the most advanced version but addComponent won't work if its already installed on that mod. Here is the file...

 

amanager_working.zip

 

I'm not sure what to do my other option is get rid of the "AddPrefabPostInit("world", function(inst)" function and load it later again though to do that I have to figure our how to manually load and save data :(

 

Or do a two component work around which is possible as long as I never change the save/load component I can channel saves and loads through it, and if it is never going to change then it won't matter what version of that component is loaded.

Link to comment
Share on other sites

LOL seriously? now I feel dumb...

Yep. :razz:

modname is the name of the mod folder (it's somewhat of a misnomer, it comes from the days before modinfo.lua was introduced), and MODROOT is the full path to it (including the trailing slash).

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...