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

[Help] Unexpected Identifier

on("change:token", function (obj) { if(obj.get("represents") == '') return; var oCharacter = getObj('character', obj.get("_represents")); var cBy = oCharacter.get('controlledby'); var oBase-AC-Value = findObjs({_type: "attribute",name: "Base-AC-Value",_characterid: oCharacter.id})[0]; var oArmor-Bonus = findObjs({_type: "attribute",name: "Armor-Bonus",_characterid: oCharacter.id})[0]; var oDexterity = findObjs({_type: "attribute",name: "Dexterity",_characterid: oCharacter.id})[0]; var oAC = findObjs({_type: "attribute",name: "AC",_characterid: oCharacter.id})[0]; var oDodge-Bonus = findObjs({_type: "attribute",name: "Dodge-Bonus",_characterid: oCharacter.id})[0]; var oNatural-AC = findObjs({_type: "attribute",name: "Natural-AC",_characterid: oCharacter.id})[0]; var oShield-Bonus = findObjs({_type: "attribute",name: "Shield-Bonus",_characterid: oCharacter.id})[0]; var oDeflection = findObjs({_type: "attribute",name: "Deflection",_characterid: oCharacter.id})[0]; var oAC-Penalty = findObjs({_type: "attribute",name: "AC-Penalty",_characterid: oCharacter.id})[0]; var oSpecial-AC-Wis = findObjs({_type: "attribute",name: "Special-AC-Wis",_characterid: oCharacter.id})[0]; var o oSpecial-AC-Int = findObjs({_type: "attribute",name: " oSpecial-AC-Int",_characterid: oCharacter.id})[0]; if(oBase-AC-Value == undefined || oDexterity == undefined || oAC == undefined || oDodge-Bonus || oNatural-AC == undefined || oDeflection == undefined || oShield == undefined || oArmor-Bonus == undefined || oAC-Penalty== undefined || oSpecial-AC-Wis== undefined || oSpecial-AC-Int== undefined) return; //Dexterity----------------- var cDexterity = parseInt(oDexterity.get("current")); var mDexterity = parseInt(oDexterity.get("max")); //Base-AC-Value----------------- var cBase-AC-Value = parseInt(oBase-AC-Value.get("current")); var mBase-AC-Value = parseInt(oBase-AC-Value.get("max")); //Deflection----------------- var cDeflection = parseInt(oDeflection.get("current")); var mDeflection = parseInt(oDeflection.get("max")); //Natural-AC----------------- var cNatural-AC = parseInt(oNatural-AC.get("current")); var mNatural-AC = parseInt(oNatural-AC.get("max")); //Dodge-Bonus----------------- var cDodge-Bonus = parseInt(oDodge-Bonus.get("current")); var mDodge-Bonus = parseInt(oDodge-Bonus.get("max")); //Shield-Bonus----------------- var cShield-Bonus = parseInt(oShield-Bonus.get("current")); var mShield-Bonus = parseInt(oShield-Bonus.get("max")); //Armor-Bonus----------------- var cArmor-Bonus = parseInt(oArmor-Bonus.get("current")); var mArmor-Bonus = parseInt(oArmor-Bonus.get("max")); //Special-AC-Wis----------------- var cSpecial-AC-Wis = parseInt(oSpecial-AC-Wis.get("current")); var mSpecial-AC-Wis = parseInt(oSpecial-AC-Wis.get("max")); //Special-AC-Int----------------- var cSpecial-AC-Int = parseInt(oSpecial-AC-Int.get("current")); var mSpecial-AC-Int = parseInt(oSpecial-AC-Int.get("max")); //AC-Penalty----------------- var cAC-Penalty = parseInt(oAC-Penalty.get("current")); var mAC-Penalty = parseInt(oAC-Penalty.get("max")); //SetMax----------------------------- var mAC = +mDexterity + +mBase-AC-Value+ +mSpecial-AC-Int+ +mAC-Penalty+ +mSpecial-AC-Wis+ +mShield-Bonus+ +mDodge-Bonus+ +mNatural-AC+ +mDeflection; oAC.set('max', mAC); //SetCurrent---------------------- var cAC = +cDexterity + +cBase-AC-Value+ +cSpecial-AC-Int+ +cAC-Penalty+ +cSpecial-AC-Wis+ +cShield-Bonus+ +cDodge-Bonus+ +cNatural-AC+ +cDeflection; oAC.set('current', cAC); }); I initially, with the help of some other people on this site, made a script that was supposed to add two attributes together. First try was to get it to calculate a characters CMB by adding his strength and his BAB together. It worked great! However, as I decided to take the next step and make a script that calculated a characters armor-class taking everything into account (at least I think I got everything... ), I encountered a problem. The first problem was caused by some formatting mistakes, that were easily corrected. It gave me the "unexpected token" error. But I took care of that and figured that now, it would run smoothly. Instead, it gave me "Unexpected Identifier". I found another post talking about it, but I didn't manage to figure out what I did wrong. I'm very new to this, so I will not understand very technical terms. Thanks in advance.
1391846737
Lithl
Pro
Sheet Author
API Scripter
Your BIG BIG BIG problem is the names you've chosen for your attribute variables. "oBase-AC-Value" means "oBase (minus) AC (minus) Value". Your calculation for mAC and cAC is confusing; I believe it will work fine, and I understand what you're trying to write, but many of those plusses are extraneous, and lead to confusion with the increment operator. You do not need to use the identity operator on mDexterity, etc. since you already used parseInt. There is no reason to use both. on("change:token", function (obj) { if (obj.get("represents") == '') return; var oCharacter = getObj('character', obj.get("_represents")); var cBy = oCharacter.get('controlledby'); var oBaseACValue = findObjs({ _type: "attribute", name: "Base-AC-Value", _characterid: oCharacter.id })[0]; var oArmorBonus = findObjs({ _type: "attribute", name: "Armor-Bonus", _characterid: oCharacter.id })[0]; var oDexterity = findObjs({ _type: "attribute", name: "Dexterity", _characterid: oCharacter.id })[0]; var oAC = findObjs({ _type: "attribute", name: "AC", _characterid: oCharacter.id })[0]; var oDodgeBonus = findObjs({ _type: "attribute", name: "Dodge-Bonus", _characterid: oCharacter.id })[0]; var oNaturalAC = findObjs({ _type: "attribute", name: "Natural-AC", _characterid: oCharacter.id })[0]; var oShieldBonus = findObjs({ _type: "attribute", name: "Shield-Bonus", _characterid: oCharacter.id })[0]; var oDeflection = findObjs({ _type: "attribute", name: "Deflection", _characterid: oCharacter.id })[0]; var oACPenalty = findObjs({ _type: "attribute", name: "AC-Penalty", _characterid: oCharacter.id })[0]; var oSpecialACWis = findObjs({ _type: "attribute", name: "Special-AC-Wis", _characterid: oCharacter.id })[0]; var ooSpecialACInt = findObjs({ _type: "attribute", name: " oSpecial-AC-Int", _characterid: oCharacter.id })[0]; if (oBaseACValue == undefined || oDexterity == undefined || oAC == undefined || oDodgeBonus || oNaturalAC == undefined || oDeflection == undefined || oShield == undefined || oArmorBonus == undefined || oACPenalty == undefined || oSpecialACWis == undefined || oSpecialACInt == undefined) return; //Dexterity----------------- var cDexterity = parseInt(oDexterity.get("current")); var mDexterity = parseInt(oDexterity.get("max")); //Base-AC-Value----------------- var cBaseACValue = parseInt(oBaseACValue.get("current")); var mBaseACValue = parseInt(oBaseACValue.get("max")); //Deflection----------------- var cDeflection = parseInt(oDeflection.get("current")); var mDeflection = parseInt(oDeflection.get("max")); //Natural-AC----------------- var cNaturalAC = parseInt(oNaturalAC.get("current")); var mNaturalAC = parseInt(oNaturalAC.get("max")); //Dodge-Bonus----------------- var cDodgeBonus = parseInt(oDodgeBonus.get("current")); var mDodge - Bonus = parseInt(oDodgeBonus.get("max")); //Shield-Bonus----------------- var cShieldBonus = parseInt(oShieldBonus.get("current")); var mShieldBonus = parseInt(oShieldBonus.get("max")); //Armor-Bonus----------------- var cArmorBonus = parseInt(oArmorBonus.get("current")); var mArmorBonus = parseInt(oArmorBonus.get("max")); //Special-AC-Wis----------------- var cSpecialACWis = parseInt(oSpecialACWis.get("current")); var mSpecialACWis = parseInt(oSpecialACWis.get("max")); //Special-AC-Int----------------- var cSpecialACInt = parseInt(oSpecialACInt.get("current")); var mSpecialACInt = parseInt(oSpecialACInt.get("max")); //AC-Penalty----------------- var cACPenalty = parseInt(oACPenalty.get("current")); var mACPenalty = parseInt(oACPenalty.get("max")); //SetMax----------------------------- var mAC = mDexterity + mBaseACValue + mSpecialACInt + mACPenalty + mSpecialACWis + mShieldBonus + mDodgeBonus + mNaturalAC + mDeflection; oAC.set('max', mAC); //SetCurrent---------------------- var cAC = cDexterity + cBaseACValue + cSpecialACInt + cACPenalty + cSpecialACWis + cShieldBonus + cDodgeBonus + cNaturalAC + cDeflection; oAC.set('current', cAC); }); Also: it is generally a good idea to use strict equals (===) instead of type-converting equals (==) when comparing something to an empty string or to undefined. So, if (obj.get("represents") === '') return; and if (oBaseACValue === undefined || ...etc.