Jump to content

Recommended Posts

Hi, I'm working on a custom character mod and have run into a bit of an issue regarding saving and loading data.

 

The character is set to go into a "panic mode" when their health goes below 40, and they cannot leave panic mode until their health gets back up to 90.

The only problem with this is that the "panicbutton" state is not saved when the game is restarted. Upon loading the game, the "panicbutton" is set back to "calm", and then immediatly goes into "panic" again if their health is under 40. 

local function onhealthchange(inst, data)	if inst.components.health.currenthealth > 90 and inst.panicbutton == "panicking" and inst.components.sanity.current > 30 then		inst.panicbutton = "calm"	end	if inst.components.health.currenthealth < 40 and inst.panicbutton == "calm" then		inst.panicbutton = "panicking"		inst.components.sanity:DoDelta(-50)	endendlocal fn = function(inst)	inst.panicbutton = "calm"	inst:ListenForEvent("healthdelta", onhealthchange) end

(^ like this)

 

I need a way to save the "panicbutton" state when the game saves so that when the game is loaded, the character is already in the correct state and it doesn't re-activate.

Sort of like Woodie's "Beaverness" state. But Beaverness is it's own component in the game files.

 

Can anyone point me in the right direction? Any help is appreciated! 

Edited by pickleplayer

Oh, heh. I just realized that I could probably just use Woodie's "Beaverness" component instead of trying to make my own "panicbutton", since Beaverness is already programmed into the game and saves and loads with each character.

 

So I did just that, and it does seem to work!

though I've barely tested it out, so I don't know if there will be any side effects to using this component (like changing forms during a full moon)

 

So I guess I've solved my own problem for now.

 

But still, if anyone happens to know another solution that doesn't involve using "beaverness", I'd be gratefull! Since I'll probably need to use more than one in the future

inst.OnSave = function(data)	return {		panicbutton = inst.panicbutton	}endinst.OnLoad = function(data)	if data then		inst.panicbutton = data.panicbutton	endend

(oops, didn't see this one)

Thank you very much! I'll try it out now

 

inst.OnSave = function(data)	return {		panicbutton = inst.panicbutton	}endinst.OnLoad = function(data)	if data then		inst.panicbutton = data.panicbutton	endend

The saving and loading work great, thanks! But There's still a problem.

Because of the [inst.panicbutton = "calm"] in my code, panicbutton always goes back to "calm" first when the game is started. And I can't just remove that line, otherwise "panicbutton" isn't declared. Any suggestions on how to fix that?

 

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