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
- Create a script that extends
CCEffectParameters. - Add it to your
CCEffectEntriesresource like any other effect. - Set Parameter Count in the Inspector and fill in each parameter.
| Property | Use |
|---|---|
parameter_N/name | Name shown to viewers, for example Total Coins. Up to 32 characters. |
parameter_N/id | ID of the parameter, for example givecoins_totalcoins. Use the effect ID as a prefix to keep it unique. |
parameter_N/kind | Item for a list of options, Range for a quantity. |
parameter_N/options | The options of an Item parameter, up to 48 characters each. |
parameter_N/min, parameter_N/max | The 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 SUCCESSget_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 SUCCESSAn 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.
