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.

EuedeAdodooedoe

Changing day time segments and so forth....

10 posts in this topic

Method No.1:

Placing files in respective folders within your mod doesn't change whatever you have changed in the files when activating the mod in-game!

So, lets say I change total_day_time (total amount of segments) from 16 to 24 (and subsequently change day_segs, night_segs and dusk_segs to correspond to this amount) in a copied tuning.lua file, which I place in [my mod]/scripts folder. Why are no changes applied to my hosted server when I host with the said mod enabled? Is there any code I need to apply in modmain.lua or elsewhere so that the tuning.lua from my mod directly replaces tuning.lua while the mod is enabled?

And yes, I know, I've heard it multiple times that file-replacement method isn't optimal for modding, but quite frankly, that's quite fine for the kind of mod that I'm making here. Although, not replacing files via modding and getting it done with a different method is preferable.

 

Method No.2:

So, aparently this mod was able to achieve the unachievable; changing local variables (or SOMETHING, somehow) to global. And it flipping works! From my understanding, this is what it in modmain to do so (this isn't the exact code of course, I just took the bits that were relevant):

seg_dtime = GetModConfigData("dspeed") * 30 / 8 --Timer segment

local total_day_time = seg_dtime * 16
local day_segs = 10
local dusk_segs = 4
local night_segs = 2

GLOBAL.TUNING.SEG_TIME = seg_dtime
GLOBAL.TUNING.TOTAL_DAY_TIME = total_day_time
GLOBAL.TUNING.DAY_SEGS_DEFAULT = day_segs
GLOBAL.TUNING.DUSK_SEGS_DEFAULT = dusk_segs
GLOBAL.TUNING.NIGHT_SEGS_DEFAULT = night_segs

However, when I put the same code, with just the seg_dtime change to seg_time (and declaring seg_time to what I want, i.e. 60) like this:

local seg_time = 60--30
local total_day_time = seg_time*24--16

local day_segs = 12--10
local dusk_segs = 6--4
local night_segs = 6--2

GLOBAL.TUNING.SEG_TIME = seg_time
GLOBAL.TUNING.TOTAL_DAY_TIME = total_day_time
GLOBAL.TUNING.DAY_SEGS_DEFAULT = day_segs
GLOBAL.TUNING.DUSK_SEGS_DEFAULT = dusk_segs
GLOBAL.TUNING.NIGHT_SEGS_DEFAULT = night_segs

NOTHING changes within the game when I enable my mod. Why? And as a result, how do I achieve this result? I believe there was another mod that changed day time. However, strangely, segment time has not been touched by any mods and I really wonder why, considering segment time, just like total day time (amount of segments) are both local variables declared in tuning.lua.

Share this post


Link to post
Share on other sites

Is it that people have had enough of me posting about this or simply don't have any answers? Or both?

Share this post


Link to post
Share on other sites

I don't have answers. I just say it so you know you aren't ignored on purpose (at least by me, but i guess it's the case for a lot of people, they don't have the answer either)

Share this post


Link to post
Share on other sites

yeah I don't have an answer or what your clearly asking I thought this was a modder problem

Share this post


Link to post
Share on other sites
48 minutes ago, Donke60 said:

yeah I don't have an answer or what your clearly asking I thought this was a modder problem

Yes, it is a modding problem. I'm basically listing two methods that I've gathered as ways of getting what I wanted to do done through my mod. The first method involves creating a copy of an original file (i.e. tuning.lua) and replacing an edited version of it from the mod within the game while the mod is running. The second method involves doing what another mod has done, as the code I present, which is done by another mod works.

However, the problem is that neither of these methods affect the game's code in any shape or form and I don't get why, so I'm trying to find a solution, but to no avail. How is one supposed to mod if the game's like "welp, this code's not gonna do jack**** just because, so GIT DUNKED BICH!"

Share this post


Link to post
Share on other sites

If the other mod is working then you're probably missing something from that mod to make it work. Perhaps study more closely on that other mod and see what all it does.

Share this post


Link to post
Share on other sites
17 hours ago, DarkKingBoo said:

If the other mod is working then you're probably missing something from that mod to make it work. Perhaps study more closely on that other mod and see what all it does.

Update: one of the things are seemingly working; the segment time. I think the segment amount is also working, however it is not displayed; the segment visuals are probably controlled somewhere else instead, which is why I'm still getting the typical "2-night lengths + 6-dusk lengths + 8 day lengths = 16 day segments" and it was a mistake on my part not paying enough attention to the speed at which the day time's bar moves at.

So now the question is where and how can I change/affect the day segment visuals, can anybody clue me in on this?

Another update: TOTAL_DAY_TIME doesn't control the amount of segments a day has, it seems. This piece of code "local NUM_SEGS = 16" I think controls the amount of segments and it's in clock.lua file, which is located in scripts/components. The thing is... the variable is GODDAMN LOCAL, so is there any way I would be able to change it without creating a copy of the file inside my mod and having it replace the file while the mod is active?

Share this post


Link to post
Share on other sites

One more update...: Sorry for double posting, but this won't get any attention I bet unless a new post is made. By random chance typing in clock.lua and, what do you know, it's where the segments are actually effected, as mentioned in the last post, however "local NUM_SEGS = 16" in clock.lua wasn't the only thing that needed to be changed; I also needed to edit the code in seasons.lua and uiclock.lua. For uiclock.lua the same kind of local variable, "local NUM_SEGS = 16" needed to be changed from 16 to 24 (the value I wanted), but for seasons.lua I needed to change the following parts of code to what they have been presented right here:

Spoiler

 

line 36 - 41


local NUM_CLOCK_SEGS = 24
local DEFAULT_CLOCK_SEGS =
{
    autumn = { day = 12, dusk = 6, night = 6 },
    winter = { day = 8, dusk = 4, night = 12 },
    spring = { day = 12, dusk = 6, night = 6 },
    summer = { day = 4, dusk = 4, night = 16 },
}

line 112 - 137


local GetModifiedSegs = _ismastersim and function(segs, mod)
	local importance = {"day", "dusk", "night"}
	table.sort(importance, function(a,b) return mod[a] < mod[b] end)

	local retsegs = {}
	for k,v in pairs(segs) do
		retsegs[k] = math.ceil(math.clamp(v * mod[k], 0, 24))
	end

	local total = retsegs.day + retsegs.dusk + retsegs.night
	while total ~= 24 do
		for i=1, #importance do
			if total >= 24 and retsegs[importance[i]] > 1 then
				retsegs[importance[i]] = retsegs[importance[i]] - 1
			elseif total < 24 and retsegs[importance[i]] > 0 then
				retsegs[importance[i]] = retsegs[importance[i]] + 1
			end
			total = retsegs.day + retsegs.dusk + retsegs.night
			if total == 24 then
			    break
			end
		end
    end

	return retsegs
end or nil

Essentially it boiled down to, again, changing everything that is 16 (number of segments clock has for days by default) to 24 and also changing the default amount of day/dusk/night segment amount for the beginnings(?) of each season accordingly.

With this I fixed one error from before, however I'm still getting this error and I cannot pinpoint why this happens and how to fix it exactly:

uiclock_error.png

Remember, I'm still using the method of "copying files into mod folder and changing them so that they replace the files while the game is running", aside from the code I mentioned at the top of this topic within modmain.lua, which I'll reiterate here, just in case:


local seg_time = 60--30
local total_day_time = seg_time*24--16

local day_segs = 12--10
local dusk_segs = 6--4
local night_segs = 6--2

GLOBAL.TUNING.SEG_TIME = seg_time
GLOBAL.TUNING.TOTAL_DAY_TIME = total_day_time
GLOBAL.TUNING.DAY_SEGS_DEFAULT = day_segs
GLOBAL.TUNING.DUSK_SEGS_DEFAULT = dusk_segs
GLOBAL.TUNING.NIGHT_SEGS_DEFAULT = night_segs


 

 

Share this post


Link to post
Share on other sites

It might be that the uiclock can't have any more (or less?) than 16 segments, at least thats what the error message implies. I'm not sure you can get past this sort of error via modding.

Share this post


Link to post
Share on other sites
On 2/13/2017 at 2:17 AM, DarkKingBoo said:

It might be that the uiclock can't have any more (or less?) than 16 segments, at least thats what the error message implies. I'm not sure you can get past this sort of error via modding.

Could @JoeW, @V2C, @Ipsquiggle, @nome, @JanH or someone else from the team confirm this? It's quite important for my mod, so if a developer/admin can give some insight on this, that would be much appreciated. If this cannot be done, I'll try to achieve something similar to what I was thinking in a different way.

 

EDIT: SOLVED! I've done it! The problem was in that I had forgotten to set one variable from 16 to 24 and the fact that I had TWO uiclock.lua files, one under widgets and another just under scripts. Deleting the wrong file from the mod and having everything done correctly enabled me to achieve this (not so) beatiful result! Feast your eyes on innovation.

Share this post


Link to post
Share on other sites