Skip to content

Creating a Parameter Effect ​

A parameter effect lets the viewer choose something when buying it: one option from a list, a quantity, or both.

Set Up the Effect ​

  1. Create a script that extends CCEffectParameters.
  2. Add it to your CCEffectEntries resource like any other effect.
  3. Set Parameter Count in the Inspector and fill in each parameter.
PropertyUse
parameter_N/nameName shown to viewers, for example Total Coins. Up to 32 characters.
parameter_N/idID of the parameter, for example givecoins_totalcoins. Use the effect ID as a prefix to keep it unique.
parameter_N/kindItem for a list of options, Range for a quantity.
parameter_N/optionsThe options of an Item parameter, up to 48 characters each.
parameter_N/min, parameter_N/maxThe bounds of a Range parameter.

Options ​

gdscript
class_name CCGiveCoins
extends CCEffectParameters


func _trigger(instance: CCEffectInstance) -> EffectResult:
	var request := instance as CCEffectInstanceParameters
	match request.get_option_name("givecoins_totalcoins"):
		"One":
			GameManager.instance.player.coins += 1
		"Five":
			GameManager.instance.player.coins += 5
	return SUCCESS

get_option_name(id) returns the name of the option the viewer picked for the parameter with that ID.

Quantity ​

Add a Range parameter with the ID quantity to let viewers buy several of an effect at once, for example a stack of items.

gdscript
class_name CCTakeCoins
extends CCEffectParameters


func _trigger(instance: CCEffectInstance) -> EffectResult:
	var request := instance as CCEffectInstanceParameters
	var quantity: int = request.get_parameter("quantity")
	GameManager.instance.player.coins = max(0, GameManager.instance.player.coins - quantity)
	return SUCCESS

An effect has a single quantity. If you add more than one Range parameter, only the first one is used. The minimum is at least 1.

Next Step ​

Continue with Creating a Timed Effect.