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

[Question] best way to handle concealment AC bonuses

Since concealment is very situational, what is the best way of handling this? Currently I am thinking to use a concealment global variable (where would I store globals?) and in my script that does gets all the AC bonuses always use this bonus, which is 0, 99% of the time. When someone does need concealment I could use a macro to change the global value to what ever... My brain hurts when I way over think these things.
1401031327
Lithl
Pro
Sheet Author
API Scripter
A global variable would be anything defined outside one of the event handler functions. As a best practice, though, you should store such things in an object specific to your script, so that you don't run the change of clashing variable names with someone else's script; this sort of "pseudo-namespacing" can be seen in most scripts people have shared: var MyScriptNamespace = MyScriptNamespace || {}; // This lets you share your namespace between scripts/tabs safely MyScriptNamespace.MyGlobalVar = 'Hello, World'; on('ready', function() { log(MyScriptNamespace.MyGlobalVar); }); However, another option is to store data in the state object. Whereas your global variables will be re-initialized every time your script sandbox spins up, the state object is saved, and persists between game sessions. There's nothing special about accessing the state object; it's simply a javascript object named "state" that you can put stuff in. It would be a good idea to "namespace" the data you put into state, though, just in case your script ever gets mixed with someone else's trying to write to the same properties of state. For your specific problem, personally I would simply use a roll query (eg, /roll 1d20+?{Query Text|0}), or calculate the difference manually after the fact. Transient bonuses and penalties aren't usually worth automating, in my opinion.
1401037241

Edited 1401037589
Well for the most part, these variables start as 0 value, so I can just declare them as null at startup. Would I need to use get and set to change the value of these globals, or can I simply use MyScriptNamespace.MyGlobalVar = new value?
1401040783
Lithl
Pro
Sheet Author
API Scripter
You do not need get/set. It's a simple javascript object, not a Roll20 object.
It needs to change the value of a roll20 object... basically my AC calculation looks like this: AC = 10 + armorbonus + shieldbonus + dexmod + sizemod + natarmor + deflection + misc + temp Misc and Temp are two of the global variables. So before the player makes his roll I have a macro that calls a script to set them so they effect the roll. This way I eliminate the need to have fewer boxes for the player to set up and manage.