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] Proper IF syntax

1435111436

Edited 1435114153
Context: I am a gamer with an understanding of the very basics of coding. Situation: I am working on modifying the API script "The Darkness Is Closing In" to check for whether the character has the "All Players See Light" checkbox checked. The unaltered script is: on("change:token", function(obj, prev) { //Only do this if we actually moved. if(obj.get("left") == prev["left"] && obj.get("top") == prev["top"]) return; obj.set({ light_radius: Math.floor(obj.get("light_radius") * 0.90) }); }); Issue: I am unable to properly format the new IF line. The plain language is: "If All Players See Light property is false, then return (don't execute the remainder of the script). This is what I currently have written that is not correctly catching the instance where the condition where property is false (unchecked): on("change:token", function(obj, prev) { //Only do this if we actually moved. if(obj.get("left") == prev["left"] && obj.get("top") == prev["top"]) return; if(obj.get("light_otherplayers") !== false) return; obj.set({ light_radius: Math.floor(obj.get("light_radius") * 0.90) }); }); Any assistance as to the proper syntax would be appreciated.
The sense of your statement is opposite of the behavior you described: "!==" means "is not identical to", so you're taking the early exit if the "light_otherplayers" property is not "false". You want "===" (really, you probably want "==", because you probably want to take the early exit for all falsey values -- e.g. 0, "", null, etc. -- not just false).
1435116032
The Aaron
Pro
API Scripter
So, with Manveti's thoughts: on("change:token", function(obj, prev) { //Only do this if we actually moved. (and all players see light) if( (obj.get("left") == prev["left"] && obj.get("top") == prev["top"]) || !obj.get("light_otherplayers")) { return; } obj.set({ light_radius: Math.floor(obj.get("light_radius") * 0.90) }); });
Excellent. That did it.