Skip to main content
Participant
January 29, 2022
Question

Trying to use a code I wrote in VSC in Adobe, need help with how to implement.

  • January 29, 2022
  • 2 replies
  • 464 views

Hello, I am trying to create a PDF GM Screen for my personal use running a D&D campaign. I've wrote in VSC the following code that displays a random critical effect:

 

const critB = ["Crunch: Target is sickened 3.", "Where Am I?: Normal damage. Target is stunned 2", "Surprise Opening: Until end of turn you gain an additional action to use as an attack against the target.",
 "Cracked Rib: Target is fatigued.", "Feeble Parry: Target drops one weapon.", "Cracked Knee: Until healed the target is clumsy 2 and takes a -5-foot status penalty to land Speed.",
 "Bell Ringer: Target is sickened 2 and is stupefied 2 until no longer sickened.", "Split Open: Target takes 1d6 persistent bleed damage.", "Momentum: Gain a +2 circumstance bonus to all attack rolls until next turn.",
 "I See Stars: Normal damage. Target is dazzled until healed.", "Broken Nose: Target takes 1d4 persistent bleed damage.", "Crushed Toe: Normal damage. Until healed target is clumsy 2 and takes a -10-foot status penalty to land Speed.",
 "Numbing Blow: Normal damage. Target is clumsy 1 for 1 minute and must succeed a Reflex save or drop 1 item it holds at random.", "Crumpling Blow: Target is knocked prone", "Shattered Hand: Normal Damage. Until healed, target is clumsy 2 and enfeebled 2, and can't use one of its hands.",
 "Two For One: Deal normal damage to one target adjacent to the original target.", "And Stay Down!: Normal damage. Target is knocked prone and stunned 2.", "Rattled: Normal damage. Target is confused for 1 round.",
 "Nighty Night: Normal damage. Target falls unconscious and can't wake up until the end of its next turn.", "Brained: Target is stunned 1.", "Collapsed Lung: Normal damage. Until healed, target is enfeebled 2 and fatigued.",
 "Bone Masher: Normal damage. Either target is clumsy 2 and takes a -10-foot status penalty to land Speed OR is clumsy 2 and can't use one of its arms (your choice). Either effect lasts until healed.", "Overwhelming Smash: Triple damage.", "Ruptured Spleen: Normal damage. Target takes 1 persistent bleed damage that can't be removed until the target has been subject to magical healing.",
 "Off Balance: Normal damage. The target triggers reactions as if it just used a move action. It is also flat-footed until the end of its next turn.", "Crushed Intestines: Normal damage. Target is wounded 2 and enfeebled 2 until it is no longer wounded.", "Crushed Trachea: Target is suffocating until subject to magical healing. It can't speak while suffocating.",
 "Skull Crush: Target is stupefied 3 until healed.", "Caved Skull: Triple damage. Target must succeed at a Fortitude save or die.", "To Your Thinky Bits: Target is stupefied 2 until healed.",
 "Dazing Thud: Target is stunned 1.", "Clocked!: Triple damage. Target is knocked prone.", "Broken Ribs: Normal damage. Target is slowed 1 until healed.",
 "Staggering Blow: Target is stunned 2.", "Thunder Strike: Target is deafened until healed.", "Box The Ears: Target is deafened until healed.",
 "Concussion: Normal damage. Target is confused for 1 minute and stupefied 2 until healed.", "Armor Dent: Normal damage. Deal the same amount of damage to the target's armor, ignoring that armor's hardness.", "Soul-Crushing Blow: Target is doomed 1 and is stupefied 1 as long as it is doomed.",
 "Breathless: Target is fatigued.", "Broken Leg: Target takes a -15-foot penalty to its land Speed until healed.", "Shield Smack: Target must succeed at a Reflex save or drop a shield it's holding.",
 "My Teef!: Target must succeed at a DC 5 flat check to cast spells with the verbal component until healed.", "Knockback: Target is pushed 1d4x5 feet away.", "Low Blow: Target is sickened 2 and slowed 1 as long as it remains sickened.",
 "Busted Shin: Until healed, target is clumsy 1 and takes a -10-foot status penalty to its land Speed.", "Back Breaker: Until healed, the target is clumsy 2 and enfeebled 2.", "Busted Shin: Until healed, the target is clumsy 1 and takes a -10-foot status penalty to its land Speed.",
 "Solid Blow: Triple damage.", "Tiring Blow: Target is fatigued.", "Foot Smash: Target is flat-footed util the end of its next turn.",
 "Lights Out: Target is blinded until the end of its next turn.", "Roundhouse: Make one additional attack against a foe adjacent to the original target, using the same attack modifier as the original attack."];
const randomCrit = critB[Math.floor(Math.random() * critB.length)];

console.log("random crit =>", randomCrit);
 
I can run the code in VSC just fine, but I want to create fields in Adobe and have the effect displayed after a button is pressed. So far I've tried just testing the code out in the Adobe console but I keep getting these types of errors:
 
TypeError: redeclaration of const critB
1:Console:Exec
undefined
TypeError: console.log is not a function
1:Console:Exec
undefined
 
Any help with this? I am definitely an amateur at all of this.
This topic has been closed for replies.

2 replies

Legend
January 30, 2022

The reason for the specific TypeError: redeclaration of const critB error is that you cannot define two constants with the same name, nor redefine the same constant. Since you put it on a button, each time the button is clicked (after the first) you are doing exactly that. You need to NOT use const. Or, define the constant only once, for example by defining it at a document level rather than inside the button.

Bernd Alheit
Community Expert
Community Expert
January 30, 2022

Change const to var.

Use console.println for Acrobat.