Converting Spell slots to Sorcery Points and vice versa in 5e

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
betavash
Kobold
Posts: 4
Joined: Fri Oct 16, 2020 10:14 pm

Converting Spell slots to Sorcery Points and vice versa in 5e

Post by betavash »

So, I am making class specific macros for my players. I have been able to find many different macros and tweak them to function with my campaign properties since I don't know much coding. While a lot have been working, I am having trouble with Sorcery Points for the Sorcerer Class. I tried many different functions, but they all ended with errors. This is the closest one I found that actually produces the result I want.

Code: Select all

<b>Convert Spell slots into Sorcery Points:</b>
<br>
[h:slot = input("slot|1,2,3,4,5|Convert Spell slot level|LIST|VALUE=STRING SELECT=0")]
[h: abort(slot)]


[r, if(slot == 1), CODE: {
	[r, if(First > 0 ), CODE: {[h:First=(First-1)][h:SorceryPoints=(SorceryPoints+1)]Converted Level 1 spell slot into 1 Sorcery Point};{No available Spell slots}]};{}]

[r, if(slot == 2), CODE: {
	[r, if(Second > 0 ), CODE: {[h:Second=(Second-1)][h:SorceryPoints=(SorceryPoints+2)]Converted Level 2 spell slot into 2 Sorcery Point};{No available Spell slots}]};{}]

[r, if(slot == 3), CODE: {
	[r, if(Third > 0 ), CODE: {[h:Third=(Third-1)][h:SorceryPoints=(SorceryPoints+2)]Converted Level 3 spell slot into 3 Sorcery Point};{No available Spell slots}]};{}]

[r, if(slot == 4), CODE: {
	[r, if(Fourth > 0 ), CODE: {[h:Fourth=(Fourth-1)][h:SorceryPoints=(SorceryPoints+2)]Converted Level 4 spell slot into 4 Sorcery Point};{No available Spell slots}]};{}]

[r, if(slot == 5), CODE: {
	[r, if(Fifth > 0 ), CODE: {[h:Fifth=(Fifth-1)][h:SorceryPoints=(SorceryPoints+2)]Converted Level 5 spell slot into 5 Sorcery Point};{No available Spell slots}]};{}]

<br>
Sorcery Points remaining: [r:SorceryPoints]
When done right it makes this result:

Convert Spell slots into Sorcery Points:
Converted Level 1 spell slot into 1 Sorcery Point

Sorcery Points remaining: 5

The issue I'm having is that it will only give the first result in the list no matter which value I choose. Is there something I'm missing or is it just not possible with this code? I don't think I will be able to figure out turning SP into slots if I can't figure this out.

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Converting Spell slots to Sorcery Points and vice versa in 5e

Post by aliasmask »

Code: Select all

[h:slot = input("slot|1,2,3,4,5|Convert Spell slot level|LIST|VALUE=STRING SELECT=0")]
[h: abort(slot)]
change to

Code: Select all

[h: abort(input("slot|1,2,3,4,5|Convert Spell slot level|LIST|VALUE=STRING SELECT=0"))]
You basically used slot for 2 different variables. First was inside your input to hold the value of the slot selected and the 2nd one, which is always one if you complete the input. The return of input() function is either 0 or 1, 0 for a cancelled input and 1 if not cancelled.

betavash
Kobold
Posts: 4
Joined: Fri Oct 16, 2020 10:14 pm

Re: Converting Spell slots to Sorcery Points and vice versa in 5e

Post by betavash »

aliasmask wrote:
Sat Oct 31, 2020 9:07 pm
You basically used slot for 2 different variables. First was inside your input to hold the value of the slot selected and the 2nd one, which is always one if you complete the input. The return of input() function is either 0 or 1, 0 for a cancelled input and 1 if not cancelled.


It works,thank you so much!! I never saw it set up like that in any of the macros that I used. Is it possible to use it in reverse as well? Like turning points into slots?

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Converting Spell slots to Sorcery Points and vice versa in 5e

Post by aliasmask »

I'm not too sure about what you're asking, but I often make 2 relational lists. One is for the input and the other is for the info I want. This is handy when your input has html or just extra stuff you don't want in final result. It also replaces the need to go though all the options after the input using if() statements to get desired results.

Code: Select all

[H: list.input = "1 point, 2 points, 4 points"]
[H: list.values = "1,2,4"]

[H: abort(input(strformat("select|%{list.input}|Select|LIST")))]
[H: result = listGet(list.values,select)]
The items in the first list corresponds to the 2nd list, so the input variable "select" holds the index of the users choice for both lists.

Post Reply

Return to “Macros”