FurryEskimo Posted September 24, 2020 Share Posted September 24, 2020 (edited) It just came to my attention that the 'sleepingbag' component was doing many of my custom tent's effects, making some of the code I wrote redundant. Well, apparently the tent acts all weird when I remove the component, but it's fine, I'll just tell the sleeping bag components to update, that's easy! Except, for some reason the code is running, and as far as I can tell the values are updating, but the tent just acts like it had default stats.. local function onsleeptick(inst, sleeper) print("Preparing sleep data.") if sleeper.components.sanity ~= nil and sleeper.components.sanity:GetPercentWithPenalty() < 0.5 then --If the sleeper's sanity value is not above 50%. TUNING.SLEEP_SANITY_PER_TICK = -10 print("Sanity data = Bellow 50%") elseif sleeper.components.sanity ~= nil and sleeper.components.sanity:GetPercentWithPenalty() > 0.5 then --If the sleeper's sanity value is above 50%. TUNING.SLEEP_SANITY_PER_TICK = 0 print("Sanity data = Above 50%") else TUNING.SLEEP_SANITY_PER_TICK = -20 print("Sanity data = Other condition") end print("Done with sleep data.") end Note: These values are just examples, but the tent can only heal you to a certain percent. There's no defined value to make this happen, so I did it myself. The log reads: [00:01:17]: Preparing sleep data. [00:01:17]: Sanity data = Above 50% [00:01:17]: Done with sleep data. [00:01:18]: Preparing sleep data. [00:01:18]: Sanity data = Above 50% [00:01:18]: Done with sleep data. Obviously it's running, and it knows my character's stats, but it's not adjusting the stat tick rate like I told it to. If I update the tick rate in "local function common_fn(bank, build, icon, tag, onbuiltfn)" it works. I was excited about this because it's easy.. Edited September 24, 2020 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/121956-onsleeptick-not-updating-values/ Share on other sites More sharing options...
penguin0616 Posted September 24, 2020 Share Posted September 24, 2020 (edited) @FurryEskimo First off, you should NOT be modifying TUNING.SLEEP_SANITY_PER_TICK, because that will affect EVERY sleepingbag relying on that variable. Second, You need to add your own custom tick rate and put that in the sleeping stuff. I've little to no idea how it works, but fixing the outlined issue should put you on the right direction or inadvertently fix the issue. Edited September 24, 2020 by penguin0616 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/121956-onsleeptick-not-updating-values/#findComment-1373763 Share on other sites More sharing options...
FurryEskimo Posted September 24, 2020 Author Share Posted September 24, 2020 @penguin0616 Right you are, it's messing up other structures. Someone else told me that if I add my own "function SleepingBagUser:SleepTick()" the sleepingbag function might prioritize my version. Not sure if that's true or not. And I did have my own version of all this code, it's just hard to say now how much of my own code was actually running, now that I know two versions of it were basically running at the same time. It was only when doing this specific testing did I notice the rates didn't match what I had coded. Link to comment https://forums.kleientertainment.com/forums/topic/121956-onsleeptick-not-updating-values/#findComment-1373770 Share on other sites More sharing options...
penguin0616 Posted September 24, 2020 Share Posted September 24, 2020 (edited) @FurryEskimo It's less of a "prioritize" and more of a "you replaced the old one, so you have to use this new one". But it is still technically true. You'll probably want to overwrite it specifically for your prefab though with AddPrefabPostInit(). If you have two versions of it running (1 client 1 server), then you probably put :AddComponent() before the mastersim check. And if you don't know how much of your code is running, add more prints until you know. That's pretty much always the solution. Edited September 24, 2020 by penguin0616 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/121956-onsleeptick-not-updating-values/#findComment-1373776 Share on other sites More sharing options...
FurryEskimo Posted September 24, 2020 Author Share Posted September 24, 2020 (edited) @penguin0616 I got it! You were right too, that my tinkering with the values was wrong and it messed with all the other structures, but I think I figured it out. I needed to change the sleeper's values, not the base values. Let me show you: local function onsleeptick(inst, sleeper) --Note: A lot of this is handled by the 'sleepingbag' component. if sleeper.components.sanity ~= nil and sleeper.components.sanity:GetPercentWithPenalty() <= 0.5 then --If the sleeper's sanity value is at or bellow 50%. inst.components.sleepingbag.sanity_tick = TUNING.SLEEP_SANITY_PER_TICK * 1 elseif sleeper.components.sanity ~= nil and sleeper.components.sanity:GetPercentWithPenalty() > 0.5 then --If the sleeper's sanity value is above 50%. inst.components.sleepingbag.sanity_tick = TUNING.SLEEP_SANITY_PER_TICK * 0 end if sleeper.components.health ~= nil and sleeper.components.health:GetPercentWithPenalty() <= 0.5 then --If the sleeper's health value is at or bellow 50%. inst.components.sleepingbag.health_tick = TUNING.SLEEP_HEALTH_PER_TICK * 1 elseif sleeper.components.health ~= nil and sleeper.components.health:GetPercentWithPenalty() > 0.5 then --If the sleeper's health value is above 50%. inst.components.sleepingbag.health_tick = TUNING.SLEEP_HEALTH_PER_TICK * 0 end if sleeper.components.temperature ~= nil then if sleeper.components.temperature:GetCurrent() > TUNING.SLEEP_TARGET_TEMP_TENT - 16 then --Target temperature is now ~25 degrees. (Default is ~40 degrees.) sleeper.components.temperature:SetTemperature(sleeper.components.temperature:GetCurrent() - TUNING.SLEEP_TEMP_PER_TICK * 2) --Rate of temperature change is increased. end if sleeper.components.temperature:GetCurrent() < TUNING.SLEEP_TARGET_TEMP_TENT -16 then sleeper.components.temperature:SetTemperature(sleeper.components.temperature:GetCurrent() + TUNING.SLEEP_TEMP_PER_TICK * 2) end end end The rate of hunger and dryness were defined elsewhere: inst:AddComponent("sleepingbag") --Automatically controls what happens when a player is sleeping in the den. inst.components.sleepingbag.onsleep = onsleep inst.components.sleepingbag.onwake = onwake inst.components.sleepingbag.hunger_tick = TUNING.SLEEP_HUNGER_PER_TICK * 1 -- inst.components.sleepingbag.health_tick = TUNING.SLEEP_HEALTH_PER_TICK * 1 -- inst.components.sleepingbag.sanity_tick = TUNING.SLEEP_SANITY_PER_TICK_PER_TICK * 1 inst.components.sleepingbag.dryingrate = math.max(0, -TUNING.SLEEP_WETNESS_PER_TICK / TUNING.SLEEP_TICK_PERIOD) --Drying rate equation. Runs automatically. From what I can tell, this is working almost exactly how I wanted it to. I can control the rates, and make it so the ice den only partially heal the sleeper. It is a little weird though, that the stat arrows claim the player's stats are rising, even when they're not. At 50% the rate of increase is 0, but the arrows are pointing up. Edited September 24, 2020 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/121956-onsleeptick-not-updating-values/#findComment-1374038 Share on other sites More sharing options...
penguin0616 Posted September 24, 2020 Share Posted September 24, 2020 (edited) @FurryEskimo I wouldn't know what the issue with the stats not changing is. However, it seems you used "Sanity_tick" instead of "sanity_tick", which is probably a mistake. Edited September 24, 2020 by penguin0616 1 Link to comment https://forums.kleientertainment.com/forums/topic/121956-onsleeptick-not-updating-values/#findComment-1374152 Share on other sites More sharing options...
FurryEskimo Posted September 24, 2020 Author Share Posted September 24, 2020 @penguin0616 I had made that issue in a few places, but found them and fixed them. That one I missed because it's commented out and will never be used. Good catch though! Link to comment https://forums.kleientertainment.com/forums/topic/121956-onsleeptick-not-updating-values/#findComment-1374168 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now