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.

_Q_

Variables naming

Recommended Posts

_Q_    634

Its geeting hard to do any mod atm cause the same prefabs that are in deflaut game and in RoG have different names. In case of walls its like:

Deflaut game:

SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())

RoG version:

SpawnPrefab("collapse_small_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())

 Now the mod crashes in RoG and only cause of small name change I need to make 2 mod versions?

Share this post


Link to post
Share on other sites
SethR    1,229

Hi @_Q_. Sorry about that--not sure how it happened. We'll fix it up, but I also wanted to call your attention to the dlcsupport.lua file. There are a handful of utility functions in there to help you interface with DLC. In this case, this function IsDLCEnabled would be useful. As an example:

if IsDLCEnabled(REIGN_OF_GIANTS)    SpawnPrefab("collapse_small_fx")else    SpawnPrefab("collapse_small")end

This particular case was an oversight, but in general: going forward you very well may have to do special casing in your mod like the above example because we had to change how a bunch of stuff worked for Reign of Giants but leave it exactly as it was for the main game. Once we're finished making the DLC itself, we'll spend some time adding support for mods so you can specify mods to only work in DLC or in the main game (or as being valid for both).

Share this post


Link to post
Share on other sites
_Q_    634

Hi @_Q_. Sorry about that--not sure how it happened. We'll fix it up, but I also wanted to call your attention to the dlcsupport.lua file. There are a handful of utility functions in there to help you interface with DLC. In this case, this function IsDLCEnabled would be useful. As an example:

if IsDLCEnabled(REIGN_OF_GIANTS)    SpawnPrefab("collapse_small_fx")else    SpawnPrefab("collapse_small")end

This particular case was an oversight, but in general: going forward you very well may have to do special casing in your mod like the above example because we had to change how a bunch of stuff worked for Reign of Giants but leave it exactly as it was for the main game. Once we're finished making the DLC itself, we'll spend some time adding support for mods so you can specify mods to only work in DLC or in the main game (or as being valid for both).

So the check will work directly in prefab files?

I did that alredy but in modmain like that:

TUNING.DLC = 0if GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS) then    TUNING.DLC = 1end

and then I do in prefab file:

if TUNING.DLC == 1 then			SpawnPrefab("collapse_small_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())		else			SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())		end

If the check works directly in prefab files its much better. Not sure if the check works on world generation time also?

Share this post


Link to post
Share on other sites
SethR    1,229

Yeah, that check should work at any time/from any file. If you find that it doesn't, please let us know!

Share this post


Link to post
Share on other sites
_Q_    634

Yeah, that check should work at any time/from any file. If you find that it doesn't, please let us know!

I made modworldgenmain and DLC check like:

if GLOBAL.IsDLCEnabled(REIGN_OF_GIANTS) thenelseend

Error it generated:

...mapps/common/dont_starve/data/scripts/dlcsupport.lua:99: calling 'IsDLCEnabled' on bad self (number expected, got nil)LUA ERROR stack traceback:        =[C] in function 'IsDLCEnabled'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/dlcsupport.lua(99,1) in function 'IsDLCEnabled'        D:/Gry/Steam/steamapps/common/dont_starve/data/../mods/Islands/modworldgenmain.lua(233,1) in main chunk        =[C] in function 'xpcall'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/util.lua(439,1) in function 'RunInEnvironment'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(179,1) in function 'InitializeModMain'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(158,1) in function 'LoadMods'        scripts/main.lua(222,1) in function 'ModSafeStartup'        scripts/main.lua(267,1)        =[C] in function 'SetPersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(17,1) in function 'SavePersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(58,1)        =[C] in function 'GetPersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(45,1) in function 'BeginStartupSequence'        scripts/main.lua(266,1) in function 'callback'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(268,1)        =[C] in function 'GetPersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(248,1) in function 'Load'        scripts/main.lua(265,1) in main chunk

Without the GLOBAL it was nil value, so ti dosent work during world generation.

Share this post


Link to post
Share on other sites
SethR    1,229

I made modworldgenmain and DLC check like:

if GLOBAL.IsDLCEnabled(REIGN_OF_GIANTS) thenelseend

Error it generated:

...mapps/common/dont_starve/data/scripts/dlcsupport.lua:99: calling 'IsDLCEnabled' on bad self (number expected, got nil)LUA ERROR stack traceback:        =[C] in function 'IsDLCEnabled'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/dlcsupport.lua(99,1) in function 'IsDLCEnabled'        D:/Gry/Steam/steamapps/common/dont_starve/data/../mods/Islands/modworldgenmain.lua(233,1) in main chunk        =[C] in function 'xpcall'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/util.lua(439,1) in function 'RunInEnvironment'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(179,1) in function 'InitializeModMain'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(158,1) in function 'LoadMods'        scripts/main.lua(222,1) in function 'ModSafeStartup'        scripts/main.lua(267,1)        =[C] in function 'SetPersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(17,1) in function 'SavePersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(58,1)        =[C] in function 'GetPersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(45,1) in function 'BeginStartupSequence'        scripts/main.lua(266,1) in function 'callback'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(268,1)        =[C] in function 'GetPersistentString'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(248,1) in function 'Load'        scripts/main.lua(265,1) in main chunk

Without the GLOBAL it was nil value, so ti dosent work during world generation.

 

Oh, you know what? You'll probably need to declare the REIGN_OF_GIANTS variable to be global as well.

Try:

If GLOBAL.IsDLCInstalled(GLOBAL.REIGN_OF_GIANTS) then  --blahelse  --blahend

Share this post


Link to post
Share on other sites
_Q_    634

I'm always forgetting about that GLOBAL before variables:P

No need to be mad.

Share this post


Link to post
Share on other sites
_Q_    634

 

Oh, you know what? You'll probably need to declare the REIGN_OF_GIANTS variable to be global as well.

Try:

If GLOBAL.IsDLCInstalled(GLOBAL.REIGN_OF_GIANTS) then  --blahelse  --blahend

So in the end it didnt work. I tried it like above and its getting error during worldgen:

D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(144,1) Loading mod: Islands	D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(168,1) Mod: workshop-225675650 (Map Revealer)	Loading modworldgenmain.lua	D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(176,1) Mod: workshop-225675650 (Map Revealer)	  Mod had no modworldgenmain.lua. Skipping.	D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(168,1) Mod: Islands	Loading modworldgenmain.lua	D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(182,1) Mod: Islands	  Error loading mod!...dont_starve/data/../mods/Islands/modworldgenmain.lua:10: variable 'IsDLCInstalled' is not declaredLUA ERROR stack traceback:        =[C] in function 'error'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/strict.lua(23,1)        D:/Gry/Steam/steamapps/common/dont_starve/data/../mods/Islands/modworldgenmain.lua(10,1) in main chunk        =[C] in function 'xpcall'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/util.lua(439,1) in function 'RunInEnvironment'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(179,1) in function 'InitializeModMain'        D:/Gry/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(158,1) in function 'LoadMods'        scripts/worldgen_main.lua(75,1) in main chunk	scripts/worldgen_main.lua(80,1) running worldgen_main.lua

Results are the same if I make it:

If GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS) then  --blahelse  --blahend

Share this post


Link to post
Share on other sites
simplex    2,608

I made modworldgenmain and DLC check like:

Oh, you know what? You'll probably need to declare the REIGN_OF_GIANTS variable to be global as well.

Try:

If GLOBAL.IsDLCInstalled(GLOBAL.REIGN_OF_GIANTS) then  --blahelse  --blahend

DLC check during worldgen does not work. I quote worldgen_main.lua:

-- THE FOLLOWING IS BROKEN - You cannot get to TheSim from world gen thread.--require("dlcsupport")
Without dlcsupport.lua being loaded (which it can't, due to the hard dependency on TheSim and the fact that the worldgen thread has WorldSim instead), we can't properly detect whether RoG is enabled or not.

This is a major issue when defining a custom level with RoG-specific overrides, like "autumn" for season_start (which causes a crash when RoG is not enabled in the colourcube manager, since the invalid season placed in the seasonmanager has no corresponding colourcube). What I'm having to do in Up and Away is patch PopulateWorld() (in gamelogic.lua) to check for the presence of RoG in the main thread, and if it is not enabled do a translation of overrides directly from savedata.map.topology.overrides. Though this is of course not ideal, and doesn't take care of all circumstances where one might need to know at worldgen whether a save is using RoG or not.

If this could be addressed soon-ish, by removing the dependency of dlcsupport.lua on TheSim and loading it at worldgen, it would be greatly appreciated.

Share this post


Link to post
Share on other sites
bizziboi    1,856

If this could be addressed soon-ish, by removing the dependency of dlcsupport.lua on TheSim and loading it at worldgen, it would be greatly appreciated.

 

 

Hi Simplex,

 

I am trying to figure out what exactly you need (well okay, you managed to work your way around it). I can easily expose whether DLC is enabled to WorldSim, but am unsure if that alone gets you where you need to be.

 

Kaj

Share this post


Link to post
Share on other sites
simplex    2,608

Hi Simplex,

 

I am trying to figure out what exactly you need (well okay, you managed to work your way around it). I can easily expose whether DLC is enabled to WorldSim, but am unsure if that alone gets you where you need to be.

 

Kaj

That would be enough. The issue is the inability to check at worldgen if RoG is enabled, in order to get mods compatible with games having either RoG enabled or say (for example, say a map should start at an "easy" season; in vanilla, this would be summer, but in RoG autumn is the new summer, so checking for RoG is necessary to provide equivalent outcomes to the player in both scenarios).

So having something equivalent to TheSim:IsDLCEnabled() at worldgen would do the trick (preferably wrapped in a global IsDLCEnabled function as is done in the main thread, for API uniformity). An equivalent version of TheSim:IsDLCInstalled() at worldgen might also be helpful, though I can't think of any particular use case for it relevant at worldgen.

Share this post


Link to post
Share on other sites
bizziboi    1,856

Hey Simplex,

 

Thanks - IsDLCEnabled() should be available at worldgen in the next release.

 

Kaj

Share this post


Link to post
Share on other sites
simplex    2,608

Hey Simplex,

 

Thanks - IsDLCEnabled() should be available at worldgen in the next release.

 

Kaj

bizziboi, I appreciate the concern and effort you put into this, but I just got the latest release and... dlcsupport_worldgen.lua does not quite work:

scripts/dlcsupport_worldgen.lua:11: variable 'i' is not declaredLUA ERROR stack traceback:        =[C] in function 'error'        scripts/strict.lua(23,1)        scripts/dlcsupport_worldgen.lua(11,1) in function 'IsDLCEnabled'        ../mods/Sandbox/modworldgenmain.lua(1,1) in main chunk        =[C] in function 'xpcall'        scripts/util.lua(439,1) in function 'RunInEnvironment'        scripts/mods.lua(179,1) in function 'InitializeModMain'        scripts/mods.lua(158,1) in function 'LoadMods'        scripts/worldgen_main.lua(74,1) in main chunk
the error here being caused by a typo at dlcsupport_worldgen.lua:

function IsDLCEnabled(index)    return __DLCEnabledTable[i] or falseend
The index used in __DLCEnabledTable should be the parameter 'index', not 'i'.

However, there's a more pressing issue with the way dlcsupport_worldgen.lua has been implemented. The presence of DLCs is being set at the end of worldgen_main.lua, fetched from the decoding of the JSON worldgen parameters:

local function LoadParametersAndGenerate(debug)	local parameters = nil	if GEN_PARAMETERS == "" then		print("WARNING: No parameters found, using defaults. This should only happen from the test harness!")		parameters = { level_type="adventure", current_level=5, adventure_progress=3, profiledata={unlocked_characters={wes=true}} }	else		parameters = json.decode(GEN_PARAMETERS)	end        if 	parameters.world_gen_choices == nil then		parameters.world_gen_choices = {}    end	SetDLCEnabled(parameters.DLCEnabled)	return GenerateNew(debug, parameters)-- parameters.worldgen_type, parameters.level_type, parameters.current_level, parameters.world_gen_choices)endreturn LoadParametersAndGenerate(false)
However, mods are loaded long before that:

require("mods")require("modindex")local moddata = json.decode(GEN_MODDATA)if moddata then	KnownModIndex:RestoreCachedSaveData(moddata.index)	ModManager:LoadMods(true)endrequire("map/tasks")print ("running worldgen_main.lua\n")
so when mods run the info about which DLCs are enabled has not been set yet, and at worldgen we don't have hooks like AddSimPostInit to delay execution of mod code until that information is available (not to mention adding new levels, the main use scenario of IsDLCEnabled, cannot be delayed, since the level data is used shortly after when generating the level).

Can this information not be made available in a sim query fashion as in the main thread, via a WorldSim:IsDLCEnabled(index) call? Or, if this is not possible, at least be passed in a separate JSON object loaded early, as is done with GEN_MODDATA?

Share this post


Link to post
Share on other sites
bizziboi    1,856

[Oh, darn, and I tested it....which is somewhat interesting, wondering if I made the classic...ehh, mistake, of changing something after testing and before checking in, although I am fairly sure I didn't.]

 

Anyhow, yes, I was initially planning to add it as a function on WorldSim but after some chatting here I decided to do it this way (excluding said typo), but I see how that won't help you. I'll try to get that in (and tested - I'll check if it's valid before "require 'mods'")

 

Apologies for the glitching, I am sadly not very familiar with the modding system (yet)

 

Kaj

Share this post


Link to post
Share on other sites
simplex    2,608

Anyhow, yes, I was initially planning to add it as a function on WorldSim but after some chatting here I decided to do it this way (excluding said typo), but I see how that won't help you. I'll try to get that in (and tested - I'll check if it's valid before "require 'mods'")

Sorry to bother you, but seeing as this didn't make the April 24 update, will it be implemented for the Steam release?

Share this post


Link to post
Share on other sites
bizziboi    1,856

Hi Simplex,

 

Yes it will, the fix is checked in - apologies for the wait, we had a slight miscommunication here regarding the CL.

 

Kaj

Share this post


Link to post
Share on other sites
simplex    2,608

Hi Simplex,

 

Yes it will, the fix is checked in - apologies for the wait, we had a slight miscommunication here regarding the CL.

 

Kaj

Thanks for the added dlc support at worldgen, it is working as intended.

Share this post


Link to post
Share on other sites
bizziboi    1,856

Thanks for the added dlc support at worldgen, it is working as intended.

 

And thanks for letting me know (o:

Share this post


Link to post
Share on other sites