Values

From Cosmoteer Wiki
< Modding‎ | ComponentsModding/Components/Values
Jump to navigation Jump to search
CalloutIconWarning.png
Work in Progress
This page is currently WORK IN PROGRESS. Some things may be missing.

Feel free to contribute and don't worry about perfection - other editors can make corrections if necessary. Just get creating!

A value is a component that can be used to store and possibly transfer a number. It can be referenced to that end.

Technically, it implements IPartComponentValue.

They have strong ties to 🔮 Buffs.

Values or related

Perhaps more surprisingly :

Maybe also :

  • MultiValueMode

Notes

Moving numbers between Buffs and Values

It's important to bring up how to move numbers between a Buff and a Value. Some operations are easier with 🔮 Buffs, others with Values.

If you have a Buff and want a Value, most values are implemented as BuffableFloats.

The BuffableValue component is the most straightforward way to move a Buff into a Value. If you have a Value and want a Buff, use a SelfBuffProvider. Make sure your component is capable of receiving the buff, as usual.

Taking a value delta and a derivative
.rules code
// These components demonstrate how to calculate a differential for a value that updates on regular intervals.
// This roughly achieves the following algorithm:
//   DifferentialValue = CurrentValue - PrevValue
//   PrevValue = CurrentValue
// Once you have the differential, calculating the derivative should be as simple as dividing by your update interval.

// Component ordering is somewhat important here. Cosmoteer loads components in the order they are defined in the rules file.
// This means that when a trigger fires, for example, earlier components will process it before later components.

// Note that this requires the component to be able to receive 2 additional buffs, for transferring values between components.
// These buffs are named CurrentValueBuff and ValueDeltaBuff here. It's recommended to simply have `CombineMode = Add` on both of these buffs.
// ValueDeltaBuff specifically needs `CombineMode = Add` so that it can properly compute the difference between current and previous value.

// This should trigger on a regular interval. The example uses a timer that updates every physics tick.
// Replace with your trigger component name.
UpdateTrigger
{
	Type = Timer
	Duration = 1/30
	AutoStart = true
	Repeats = true
}

// This is the Value component that you want to take derivative of.
// Replace with your value component name.
CurrentValue
{
	// ...
}

// Converts the current value to a buff, for use in a BuffableFloat down the line
CurrentValueToBuff
{
	Type = SelfBuffProvider
	BuffType = CurrentValueBuff
	BuffMultiplier = CurrentValue
}

// Converts the current value to the delta buff. This, combined with PrevValueToDeltaBuff below, computes the differential in buff space.
CurrentValueToDeltaBuff
{
	Type = SelfBuffProvider
	BuffType = ValueDeltaBuff
	BuffMultiplier = CurrentValue
}

// If the change in CurrentValue is triggered by UpdateTrigger, this component is needed here
// to ensure that CurrentValue updates before saving the differential.
SaveDeltaTrigger
{
	Type = TriggerProxy
	ComponentID = UpdateTrigger
}

// This is the output.
// The differential is stored in an accumulator to isolate it from changes in other value components.
DifferentialValue
{
	Type = ValueAccumulator
	AccumulationTriggers
	[
		{
			Trigger = SaveDeltaTrigger
			Operation = Set
			Value = { BaseValue = 1; BuffType = ValueDeltaBuff; BuffMode = Multiply; }
		}
	]
}

// This trigger proxy is placed below the other components to ensure that computing and saving DifferentialValue happens before writing CurrentValue to PrevValue.
SavePrevValueTrigger
{
	Type = TriggerProxy
	ComponentID = UpdateTrigger
}

// Store the previous value into an accumulator for the next update.
PrevValue
{
	Type = ValueAccumulator
	AccumulationTriggers
	[
		{
			Trigger = SavePrevValueTrigger
			Operation = Set
			Value = { BaseValue = 1; BuffType = CurrentValueBuff; BuffMode = Multiply; }
		}
	]
}

// Negate the previous value and add it to the delta buff. This, combined with CurrentValueToDeltaBuff above, computes the differential in buff space.
PrevValueToDeltaBuff
{
	Type = SelfBuffProvider
	BuffType = ValueDeltaBuff
	BuffAmount = -1
	BuffMultiplier = PrevValue
}

Examples

(WIP)

See also