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

Creating a Rectangle Path

After spending far too long on it, I'm throwing in the towel. What is wrong w/ this code? All I want to do is create a solid red rectangle. I'll modify it later to be dynamic. When my script executes, it creates an invisible object of the correct size. I'm guessing my path is incorrect, but I don't know how to fix it. createObj("path", { pageid: Campaign().get("playerpageid"), path: [["M", 0, 0],["L", 0, 70],["L", 70, 70],["L", 70, 0],["L", 0, 0]], fill: "#ff0000", stroke: "#ff0000", layer: "objects", stroke_width: 5, width: 70, height: 70, top: 270, left: 270, }); Thanks!
Odd. Comparing it to the model here: <a href="https://wiki.roll20.net/API:Objects#Creating_Objec" rel="nofollow">https://wiki.roll20.net/API:Objects#Creating_Objec</a>... I don't see any discrepancy other than the final comma after left: 270 When I loaded it into one of my test campaigns, it generated the following error : "Cannot call method 'get' of undefined" which I assume refers to the pathid definition line. I pasted in a version of that get from another script that I know works, and it still generated that error. I even tried pulling the get out of the createObj and use it to define a local variable, but still got the error.
I think you want to wrap your path in single quotes.
1437272591
Lithl
Pro
Sheet Author
API Scripter
Rand said: I think you want to wrap your path in single quotes. To be on the safe side, I would recommend using JSON.stringify([...stuff...]). The path property is a JSON string, and JSON.stringify will accurately turn an object or array into a correctly-formatted JSON string.
Rand said: I think you want to wrap your path in single quotes. That did the trick! Thank you! I spent hours trying to figure that one out...