Well, because I'm never happy with things the way they are and I much prefer the [rbutton] approach rather than dropdown menus I decided to do a little rewrite. I also wanted to include the creation of the rollable token table and the creation of the repeating actions as they only need to be created once as they are the same for all beast types. So, if you run the script the first time it'll check to see if the "Maul" repeating section exists on the NPC character sheet. If it doesn't, it creates the rollable table and the two repeating actions. On subsequent uses of the script it should skip the code that creates these and just run the spell code. The first time the script is run everything works out great, the rollable table and repeating actions are created, but on subsequent uses of the script it crashes the sandbox right after choosing what type of beast; the "GetBeast" section. Both scripts run fine seperately. Here's the sandbox crash message. Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your script's code and click the "Save Script" button. We will then attempt to start running the scripts again. More info... If this script was installed from the Mod Library, you might find help in the Community API Forum. For reference, the error message generated was: TypeError: Cannot read properties of undefined (reading '0')
TypeError: Cannot read properties of undefined (reading '0')
at replaceVariableContent (apiscript.js:11528:71)
at apiscript.js:8232:22
at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:65:16)
at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:70:8)
at /home/node/d20-api-server/api.js:1762:12
at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560
at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147)
at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489)
at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) Here's the debug output. "Setting parameter debug to value 1 - 1"
"Line Counter: 29, Tag:&SummonBeast, Content:-NmrmQgxSXU2sJwoVJ4g"
"Line Counter: 30, Tag:>RepeatExist, Content:"
"Line Counter: 92, Tag:Rfind, Content:-NmrmQgxSXU2sJwoVJ4g;Maul;repeating_npcaction;name"
"Line Counter: 93, Tag:&MaulExist, Content:Maul"
"ContentIn: ?\"[&MaulExist]\" -eq \"Maul\" Match: [&MaulExist], vName: MaulExist, replacement Maul"
"Line Counter: 94, Tag:?\"Maul\" -eq \"Maul\", Content:["
"Condition \"Maul\" -eq \"Maul\" evaluation result: true"
"Line Counter: 95, Tag:>WhatSpellSlot, Content:"
"Line Counter: 33, Tag:+At what level is the spell being cast?, Content:"
"Line Counter: 34, Tag:+, Content:[rbutton]2::WhatLVL;2[/rbutton][rbutton]3::WhatLVL;3[/rbutton][rbutton]4::WhatLVL;4[/rbutton][rbutton]5::WhatLVL;5[/rbutton][rbutton]6::WhatLVL;6[/rbutton][rbutton]7::WhatLVL;7[/rbutton][rbutton]8::WhatLVL;8[/rbutton][rbutton]9::WhatLVL;9[/rbutton]"
"Line Counter: 35, Tag:<, Content:"
"Line Counter: 96, Tag:], Content:["
"Line Counter: 110, Tag:X, Content:"
"Line Counter: 36, Tag::WhatLVL, Content:"
"ContentIn: [&reentryval] Match: [&reentryval], vName: reentryval, replacement 2"
"Line Counter: 37, Tag:=SlotLevel, Content:2"
"Line Counter: 38, Tag:=SlotsTotal, Content:0"
"ContentIn: [*S:lvl[$SlotLevel]_slots_expended] Match: [$SlotLevel], vName: SlotLevel, vSuffix: Total, replacement 2"
"Line Counter: 39, Tag:=SlotsExpended, Content:82"
"ContentIn: ?[$SlotsExpended.Raw] -eq [$SlotsTotal.Raw] Match: [$SlotsExpended.Raw], vName: SlotsExpended, vSuffix: Raw, replacement 82"
"ContentIn: ?82 -eq [$SlotsTotal.Raw] Match: [$SlotsTotal.Raw], vName: SlotsTotal, vSuffix: Raw, replacement 0"
"Line Counter: 40, Tag:?82 -eq 0, Content:NoSlotsLeft|MinusSlot"
"Condition 82 -eq 0 evaluation result: false"
"ContentIn: ?[$SlotLevel] -eq 0 Match: [$SlotLevel], vName: SlotLevel, vSuffix: Total, replacement 2"
"Line Counter: 43, Tag:?2 -eq 0, Content:NoSlot"
"Condition 2 -eq 0 evaluation result: false"
"ContentIn: [$SlotsExpended] - 1 Match: [$SlotsExpended], vName: SlotsExpended, vSuffix: Total, replacement 82"
"Line Counter: 44, Tag:=SlotsLeft, Content:82 - 1"
"ContentIn: _charid -NkI_fM9DSFvkPt7oP2Z _lvl[$SlotLevel]_slots_expended|[$SlotsLeft] _silent Match: [$SlotLevel], vName: SlotLevel, vSuffix: Total, replacement 2"
"ContentIn: _charid -NkI_fM9DSFvkPt7oP2Z _lvl2_slots_expended|[$SlotsLeft] _silent Match: [$SlotsLeft], vName: SlotsLeft, vSuffix: Total, replacement 81"
"Line Counter: 45, Tag:@setattr, Content:_charid -NkI_fM9DSFvkPt7oP2Z _lvl2_slots_expended|81 _silent"
"ScriptCards: Making API call - !setattr --charid -NkI_fM9DSFvkPt7oP2Z --lvl2_slots_expended|81 --silent"
"Line Counter: 46, Tag:>GetBeast, Content:"
"Line Counter: 51, Tag:+What type of Beast are you summoning?, Content:[br][rbutton]Land::Land-Beast[/rbutton][rbutton]Air::Air-Beast[/rbutton][rbutton]Water::Sea-Beast[/rbutton]"
"Line Counter: 52, Tag:X, Content:"
"Line Counter: 53, Tag::Land-Beast, Content:"
"Line Counter: 54, Tag:&Type, Content:1"
"Line Counter: 55, Tag:&hplvl, Content:30"
"ContentIn: !a:[&SummonBeast] Match: [&SummonBeast], vName: SummonBeast, replacement -NmrmQgxSXU2sJwoVJ4g"
"Line Counter: 56, Tag:!a:-NmrmQgxSXU2sJwoVJ4g, Content:!npc_name:Land Beast"
"ContentIn: [&SummonBeast];repeating_npctrait Match: [&SummonBeast], vName: SummonBeast, replacement -NmrmQgxSXU2sJwoVJ4g"
"Line Counter: 57, Tag:Rfirst, Content:-NmrmQgxSXU2sJwoVJ4g;repeating_npctrait"
"ContentIn: !a:[&SummonBeast] Match: [&SummonBeast], vName: SummonBeast, replacement -NmrmQgxSXU2sJwoVJ4g"
"Line Counter: 58, Tag:!a:-NmrmQgxSXU2sJwoVJ4g, Content:NoRepeatingAttributeLoaded:Pack Tactics|NoRepeatingAttributeLoaded:The beast has advantage on an attack roll against a creature if at least one of the beast’s allies is within 5 feet of the creature and the ally isn’t incapacitated."
"Line Counter: 59, Tag:Rnext, Content:"
"ContentIn: !a:[&SummonBeast] Match: [&SummonBeast], vName: SummonBeast, replacement -NmrmQgxSXU2sJwoVJ4g"
TypeError: Cannot read properties of undefined (reading '0')
TypeError: Cannot read properties of undefined (reading '0')
at replaceVariableContent (apiscript.js:11528:71)
at apiscript.js:8232:22
at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:65:16)
at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:70:8)
at /home/node/d20-api-server/api.js:1762:12
at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560
at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147)
at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489)
at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425)
Here's the macro script. !scriptcards {{
--#title|Summon Beast
--#sourceToken|@{selected|token_id}
--#emoteText|[*S:character_name] Casts Summon Beast.
--#bodyfontface|Helvetica
--#oddrowfontcolor|#290000
--#evenrowfontcolor|#290000
--#bodyfontsize|[&bodyFontSize]px
--#titlecardbackgroundcolor|#930c10
--#titlecardbackgroundcolor|#672223
--#titlefontcolor|#fffebd
--#titlefontsize|1.5em
--#titlefontshadow|0
--#oddrowbackground|#f7ce65
--#evenrowbackground|#f7ce65
--#oddrowbackground|#b3ab96
--#evenrowbackground|#b3ab96
--#subtitlefontcolor|#fffebd
--#tablebgcolor|#fffebd
--#lineheight|10pt
--#buttonfontsize|10px
--#buttonbackground|#930c10
--#buttonbackground|#672223
--#buttonbackground|rgba(103,34,35,1); display:inline-block;
--#buttonfontface|Tahoma
--#buttonpadding|8px
--#bodyfontface|Helvetica
--#bodyfontsize|14px
--#Debug|1
--&SummonBeast|@{SummonBeast|character_id}
-->AllExist|
--X|
--:AllExist|
--Rfind|@{SummonBeast|character_id};Maul;repeating_npcaction;name
--&MaulExist|[*R:name]
--?"[&MaulExist]" -eq "Maul"|[
-->WhatSpellSlot|
--]|[
--+|[b]Creating Rollable Token Table for First Run[/b]
--!o#:tableid|SummonBeast
--+New Table ID|[&tableid]
--!oe:entryid|[&tableid];Land-Beast
--+New Entry ID|[&entryid]
--!oe:entryid|[&tableid];Air-Beast
--+New Entry ID|[&entryid]
--!oe:entryid|[&tableid];Water-Beast
--+New Entry ID|[&entryid]
--+Rollable Token Table SummonBeast created.| Find the table under Collection and set up your Land, Air and Water beast tokens.[br]Don't forget to link your new rollable token to your SummonBeast character sheet and turn vision on. The next run of this macro will just cast the spell.
--!or:[&SummonBeast]:npcaction|
name:Maul|
attack_flag:on|
attack_type:melee|
attack_target:one target|
attack_range:5 ft.|
attack_tohit:@{selected|spell_attack_bonus}|
attack_damage:1d8 + 4 + [$SlotLevel]|
attack_damagetype:piercing|
attack_tohitrange:|
attack_range:5ft.|
attack_target:one target|
attack_onhit:1d8 + 4 + [$SlotLevel]|
description:The beast has advantage on an attack roll against a creature if at least one of the beast’s allies is within 5 feet of the creature and the ally isn’t incapacitated.
--!or:[&SummonBeast]:npcaction|name:Multiattack|description:The beast makes a number of attacks equal to half this spell’s level (rounded down).
--]|
--X|
--:WhatSpellSlot|
--+At what level is the spell being cast?|
--+|[rbutton]2::WhatLVL;2[/rbutton][rbutton]3::WhatLVL;3[/rbutton][rbutton]4::WhatLVL;4[/rbutton][rbutton]5::WhatLVL;5[/rbutton][rbutton]6::WhatLVL;6[/rbutton][rbutton]7::WhatLVL;7[/rbutton][rbutton]8::WhatLVL;8[/rbutton][rbutton]9::WhatLVL;9[/rbutton]
--<|
--:WhatLVL|
--=SlotLevel|[&reentryval]
--=SlotsTotal|0
--=SlotsExpended|[*S:lvl[$SlotLevel]_slots_expended]
--?[$SlotsExpended.Raw] -eq [$SlotsTotal.Raw]|NoSlotsLeft|MinusSlot
--X|
--:MinusSlot|
--?[$SlotLevel] -eq 0|NoSlot
--=SlotsLeft|[$SlotsExpended] - 1
--@setattr|_charid [*S:character_id] _lvl[$SlotLevel]_slots_expended|[$SlotsLeft] _silent
-->GetBeast|
--X|
--:NoSlot|
--X|
--:GetBeast|
--+What type of Beast are you summoning?|[br][rbutton]Land::Land-Beast[/rbutton][rbutton]Air::Air-Beast[/rbutton][rbutton]Water::Sea-Beast[/rbutton]
--X|
--:Land-Beast|
--&Type|1
--&hplvl|30
--!a:[&SummonBeast]|!npc_name:Land Beast
--Rfirst|[&SummonBeast];repeating_npctrait
--!a:[&SummonBeast]|[*R>name]:Pack Tactics|[*R>description]:The beast has advantage on an attack roll against a creature if at least one of the beast’s allies is within 5 feet of the creature and the ally isn’t incapacitated.
--Rnext|
--!a:[&SummonBeast]|[*R>name]:|[*R>description]:description:
-->CommonAttr|
--<|
--:Air-Beast|
--&Type|2
--&hplvl|20
--!a:[&SummonBeast]|!npc_name:Air Beast
--Rfirst|[&SummonBeast];repeating_npctrait
--!a:[&SummonBeast]|![*R>name]:Flyby|![*R>description]:The beast doesn’t provoke opportunity attacks when it flies out of an enemy’s reach.
--Rnext|
--!a:[&SummonBeast]|[*R>name]:|[*R>description]:description:
-->CommonAttr|
--<|
--:Sea-Beast|
--&Type|3
--&hplvl|30
--!a:[&SummonBeast]|!npc_name:Water Beast
--Rfirst|[&SummonBeast];repeating_npctrait
--!a:[&SummonBeast]|[*R>name]:Pack Tactics|[*R>description]:The beast has advantage on an attack roll against a creature if at least one of the beast’s allies is within 5 feet of the creature and the ally isn’t incapacitated.
--Rnext|
--!a:[&SummonBeast]|[*R>name]:Water Breathing|[*R>description]:The beast can breathe only underwater.
-->CommonAttr|
--<|
--:CommonAttr|
--=ACCalc|11 + [$SlotLevel]
--=hptotal|5 * [= [$SlotLevel] - 2] + [&hplvl]
--&Speed|30ft, 30ft climb
--!a:[&SummonBeast]|!npc_type:Medium Beast, Unaligned|!npc_ac:[$ACCalc]|!hp:[$hptotal]|!hp^:[$hptotal]|!strength_base:18|!dexterity_base:11|!constitution_base:16|!intelligence_base:4|!wisdom_base:14|!charisma_base:5|!npc_speed:[&Speed]|!npc_challenge:
--@forselected|Spawn _name|SummonBeast _offset|1,0 _side|[&Type]
--+|Level [$SlotLevel] Slots Left: [$SlotsLeft]
--<|
--:NoSlotsLeft|
--+|[*S:character_name] has no level [$SlotLevel.Total] spell slots available.
--X|NoSlotsLeftStop
}} I definitely think this has to do with table creation because my original script without it worked fine. But, I'm not running the table creation on the runs of the script after the first time. So, I am a confused person.