Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

ScriptCards String Variable as Character Name

1697892052

Edited 1697892063
Essen
Pro
Marketplace Creator
Howdy. I've set a dice game as a token action on a dice tray token. I'm trying to reference the character wallet using the player ID, which is working as far as that it will display their character name based on the player ID based on a conditional. However, when I use this same variable to try and reverence their wallet... --:FindWallet| --?"[&SendingPlayerID]" -eq "-Myw..."|[--&CharName|Char--]| --?"[&PotType]" -eq "copper"|[--&Coin|CP--]| --?"[&PotType]" -eq "silver"|[--&Coin|SP--]| --?"[&PotType]" -eq "gold"|[--&Coin|GP--]| --?"[&PotType]" -eq "plat"|[--&Coin|PP--]| --&WalletID|@{[&CharName]|[&Coin]} --=Wallet|[&WalletID] --<| I get " No character was found for '[&CharName]'" I tried making the whole thing a string, then calling it to set the number, but to no avail. How would I get this to flatten enough to work?
1697895560
Kurt J.
Pro
API Scripter
Essen said: Howdy. I've set a dice game as a token action on a dice tray token. I'm trying to reference the character wallet using the player ID, which is working as far as that it will display their character name based on the player ID based on a conditional. However, when I use this same variable to try and reverence their wallet... --:FindWallet| --?"[&amp;SendingPlayerID]" -eq "-Myw..."|[--&amp;CharName|Char--]| --?"[&amp;PotType]" -eq "copper"|[--&amp;Coin|CP--]| --?"[&amp;PotType]" -eq "silver"|[--&amp;Coin|SP--]| --?"[&amp;PotType]" -eq "gold"|[--&amp;Coin|GP--]| --?"[&amp;PotType]" -eq "plat"|[--&amp;Coin|PP--]| --&amp;WalletID|@{[&amp;CharName]|[&amp;Coin]} --=Wallet|[&amp;WalletID] --&lt;| I get " No character was found for '[&amp;CharName]'" I tried making the whole thing a string, then calling it to set the number, but to no avail. How would I get this to flatten enough to work? You can't use @{...} referencing with ScriptCards variables. This is because @{[&amp;CharName]|[&amp;Coin]} will be processed by the Chat server before ScriptCards gets passed the macro. Since the chat server doesn't know what [&amp;CharName] (or [&amp;Coin]) is, it is trying to find a character literally named [&amp;CharName], which obviously doesn't exist. You need to use ScriptCards referencing to do this, so assuming you have a way to get a character id into a variable, you would use something like &nbsp; [*[&amp;CharID]:[&amp;Coin]] Assuming Coin is set to the name of an attribute on the character sheet. This can actually be shortened up a lot by using a case statement (--c) instead of separate conditionals. It will also run faster too: Note: the following assumes that at some point you have put the character id or a token id that represents a character into a variable called [&amp;CharID] &nbsp; --c[&amp;PotType]|copper:&amp;Coin;CP|silver:&amp;Coin;SP|gold:&amp;Coin;GP|plat:&amp;Coin;PP --=Wallet|[*[&amp;CharID]:[&amp;Coin]] --&lt;| Using the sending player ID to determine a character is a small bit of work, but can be done. If you are using the system neutral library from the ScriptCards github (<a href="https://github.com/kjaegers/ScriptCards/blob/main/ScriptCards_Examples/libraries/systemneutrallib.scard" rel="nofollow">https://github.com/kjaegers/ScriptCards/blob/main/ScriptCards_Examples/libraries/systemneutrallib.scard</a>) there is a library function to do this for you (LibSN_GET_CONTROLLED_TOKENS_FROM_PAGETOKENS), which will get the tokens controlled by the sending player. ScriptCards can use the token id in place of a character id in [*...] referencing and will simply look up what character the token represents automatically. Finally, you may find you get quicker responses by posting in the ScriptCards thread instead of creating individual threads for each issue. There are several helpful folks that keep an eye on that thread and might miss new threads in the forum.
1697903355
Essen
Pro
Marketplace Creator
Thank you very much! It works perfectly. I will play around with the case statements.... I've been lining up a bunch of conditionals all over the place guiding things. I'll go back through and clean things up. For the character ID, I just manually compare it to the player ID with a conditional. ... --?"[&amp;SendingPlayerID]" -eq "-MywY8FW7DCZ8KyTDq2-"|[--&amp;CharID|-N1-q6m_933jctERK2pk--]| --c[&amp;PotType]|copper:&amp;Coin;CP|silver:&amp;Coin;SP|gold:&amp;Coin;GP|plat:&amp;Coin;PP --=Wallet|[*[&amp;CharID]:[&amp;Coin]] --&lt;| Not fancy, but it works.