Jump to content

Recommended Posts

The idea is to replace the new Day stinger with a different sound file, but only the day a new season starts, but I'm not cracked enough to be familiar with the code outside 'dynamicmusic.lua'

I've tried using an if 'inst.state.season' condition but it results on the new season sound file being used every day

 

There are a few world states you can listen for using something like this:

inst:WatchWorldState("season", OnSeasonChange)

There are also states for the specific seasons in case you wanted to have different music for each season.

Edited by MakeSureToKnock
  • Health 1
On 9/30/2024 at 3:11 AM, MakeSureToKnock said:

There are a few world states you can listen for using something like this:

inst:WatchWorldState("season", OnSeasonChange)

There are also states for the specific seasons in case you wanted to have different music for each season.

Yeah, I already have a jingle for start of Autumn, Winter, Spring and Summer prepared, regrettably I've refrained from using inst() since I don't understand them lol

If WatchWorldState really only works for the very start of a season, I was considering putting it as an " if " in place of the day check that plays the dawn stinger, and putting that as an " elseif "

Thank you for taking your time to answer btw

Inst() stands for instance and it's essentaily a call for the object that it's used in. For example, if you did something simple like print(inst) and put that in some function within the evergreen prefab, or a component attached to that prefab, it would print the name of the evergreen prefab file when the function was called. A lot of the time you'll see something like inst.components.xxx.yyy where xxx is the component name and yyy is some variable/function within the component; it let's you grab data from all over the place. So the inst:WatchWorldState would be attaching that watch to whatever object you put it in and if that object doesn't exist in the world then the watch won't happen.

At least this is my understanding of it and how it's worked for me thus far.

 

Edited by MakeSureToKnock
  • Health 1

Sorry had some stuff and kinda had to dip from editing a bit, so

On 9/30/2024 at 3:11 AM, MakeSureToKnock said:

inst:WatchWorldState("season", OnSeasonChange)

This would store the in-game's season data into a theoretical OnSeasonChange function, right? I was a bit apprehensive because the dynamicmusic file already makes use of an already existing inst:WatchWorldState("season", OnSeason) and OnSeason() combo (although it seemingly does next to nothing with it besides turning off working music); so perhaps I could make use of that existing code to call the jingles instead of creating more functions

On 9/30/2024 at 3:11 AM, MakeSureToKnock said:

There are also states for the specific seasons in case you wanted to have different music for each season.

Such as? I'd assume the data of the four seasons?

Also to reiterate, WatchWorldState would only react to the start of a new season right? not any of the subsequent days within it

On 10/30/2024 at 8:46 PM, Sukaiba said:

Sorry had some stuff and kinda had to dip from editing a bit, so

Same.

Anyway, if you haven't already found a satisfying solution.

I've done a quick look into a few more World Watch states and where they're used.

WatchWorldState("season", function())  appears in things like the bearger and dearclops spawners as well as a ton of other stuff with seasons conditions, which implies that it only triggers once on season change.

There are also watch states for "iswinter", "isspring", "issummer", and "isautum" but the name suggests these check more frequently if not constantly.

I didn't test either though so I don't know if they proc only once or not.

However, in the file worldstate.lua the local function OnSeasonTick(src, data) there are a lot of data varibles that could be used to write something so that it only triggers once. Just off the top of my head you could do something like this.

local currentSeason = nil --This would reset when whatever the game reloaded, meaning this is likely to play every time you reload the game
local function OnSeasonChange()

	if currentSeason ~= TheWorld.state.season then
    	do thing
  	end
    
	local currentSeason = TheWorld.state.season
end
  
 
inst:WatchWorldState("season", OnSeasonChage")

The idea being that you're allowing the function to do the thing™ only once because after this runs the next time it tries to during the same season the var and state will be the same. Once the season rolls over though, it'll be different and be allowed to run one time once again.

Again, I haven't tested any of this, but it should work in a similar manner.

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
×
  • Create New...