Here I am trying to create a macro to consume some uses of an ability or a spell slot. The properties are stored in the token this way (as an example). The number contained between the parenthesis symbolize the number of uses remaining and the maximum number: (3/4) means the token has 3 uses remaining out of 4.
Code: Select all
Counter1: Action Surge (1/1)
Counter2: Combat Superiority (4/4)
SpellSlotLv0: Light, Sacred Flame, Thaumaturgy
SpellSlotLv1: Command, Inflict Wounds, Shield Of Faith (4/4)
SpellSlotLv2: Hold Person, Spiritual Weapon (3/3)
My intent here is to make the macro read the spell list as a single string per property in order to get the radio buttons to be like
"Command, Inflict Wounds, Shield Of Faith (4/4) O"
instead of
"Command O
Inflict Wounds O
Shield Of Faith (4/4) O"
I tried using a different delimitator / pattern while creating the lists but it didn't work, and I don't want to use a different separator in the token property. Can someone help me?
Code: Select all
<!-- Gets selected tokens -->
[h: TokenIDs = getSelected()]
<!-- Makes sure only one token is selected -->
[h, if(listCount(TokenIDs) != 1), CODE: {
[dialog("Macro Abort"): {
You can select only one token. No token or multiple tokens are selected
}]
[h: abort(0)]
}]
<!-- Switches to token and prepares some lists -->
[h: switchToken(getSelected())]
<!-- List of Property from which to get the abilities -->
[h: CounterListPropertyName = stringToList("Counter1:Counter2:Counter3:Counter4:Counter5:SpellSlotLv0:SpellSlotLv1:SpellSlotLv2:SpellSlotLv3:SpellSlotLv4:SpellSlotLv5:SpellSlotLv6:SpellSlotLv7:SpellSlotLv8:SpellSlotLv9",":"))]
<!-- List of available abilities only -->
[h: CounterList = ""]
<!-- List of available abilities AND empty spaces -->
[h: CounterListRAW = ""]
<!-- Fills the ability lists -->
[h, foreach(Property,CounterListPropertyName,""), CODE: {
[h: CounterListRAW = listappend(CounterListRAW,getProperty(Property))]
[h, if(getProperty(Property) != ""): CounterList=listappend(CounterList,getProperty(Property))]
}]
<!-- Create Menu -->
[h: StringBuild = "SelectedAbilityID|"+CounterList+"|Select the ability|RADIO|SELECT=0"]
[h: abort(input(
"Operation|Consume,Recover|Select the operation|RADIO|SELECT=0",
"Quantity|1|Select the quantity",
StringBuild
))]
<!-- Gets the selected ability, finds the remaining uses and edit them -->
[h: SelectedAbility = listGet(CounterList, SelectedAbilityID)]
[h: MaximumUses = eval(substring(SelectedAbility, indexOf(SelectedAbility, "/")+1, indexOf(SelectedAbility, ")")))]
[h: RemainingUses = eval(substring(SelectedAbility, indexOf(SelectedAbility, "(")+1, indexOf(SelectedAbility, "/")))]
<!-- Create a permission variable and checks if the user is consuming or is recovering too much -->
[h: ExecPermission = 1]
[h, if(Operation == 0), CODE: {
[h, if(RemainingUses-Quantity < 0), CODE: {
[h: ExecPermission = 0]
};{
[h: RemainingUses = RemainingUses-Quantity]
}]
};{
[h: RemainingUses = min(RemainingUses+Quantity,MaximumUses)]
}]
<!-- If the user consumed too much, this aborts the macro and warns the user -->
[h, if(ExecPermission == 0), CODE: {
[dialog("Macro Abort"): {
You are consuming too much
}]
[h: abort(0)]
}]
<!-- Rebuilds the property value by writing the ability name -->
[h: EditedAbility = substring(SelectedAbility, 0, indexOf(SelectedAbility, "(")+1)+RemainingUses+substring(SelectedAbility, indexOf(SelectedAbility, "/"), indexOf(SelectedAbility, ")")+1)]
<!-- Gets the name of the property to edit and replace it with the edited ability -->
[h: PropertyName = listGet(CounterListPropertyName,listFind(CounterListRAW,SelectedAbility))]
[h: setProperty(PropertyName,EditedAbility)]