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] Trouble with positioning of graphic objects

So, I'm very new to using the API and to using JS (or any code). In the past few days I've cobbled together a couple scripts to create an arrangement of graphic objects using a text command. My problem right now is that some of the objects are generated on top of other instead of side by side (in the wrong place). I cannot for the life of me figure out what is wrong. I suspect its something to do with the sequence of events or some such. Here's my code: <a href="https://gist.github.com/anonymous/d94d925b8cb44065" rel="nofollow">https://gist.github.com/anonymous/d94d925b8cb44065</a>... //script to create the tokens <a href="https://gist.github.com/anonymous/bded6f7fcdea16b8" rel="nofollow">https://gist.github.com/anonymous/bded6f7fcdea16b8</a>... //script to call on the function after text event The only other part of the equation is an array containing the names and imgsrc's of the graphics. I don't think that part's malfunctioning.&nbsp; What I'm specifically trying to do is create a 3 by 3 grid of 9 objects. &nbsp;Right now the first column creates correctly, the second column is created behind the first, then the third column generates in the right place. Very perplexing for me. Thanks in advance
1450206875

Edited 1450206998
The Aaron
Pro
API Scripter
Your math for calculating the row and column is slightly off. &nbsp;For 0-9, it's generating: 105,105 105,175 105,245 105,105 105,175 105,245 245,105 245,175 245,245 Try using this function instead: var puzzle = function (slotNumber) {&nbsp; &nbsp; &nbsp; 'use strict'; &nbsp; &nbsp; var page = Campaign().get("playerpageid"), &nbsp; &nbsp; &nbsp; &nbsp; // Math.floor() drops the remainder, so this will be: &nbsp; &nbsp; &nbsp; &nbsp; // 0 0 0 1 1 1 2 2 2 .... &nbsp; &nbsp; &nbsp; &nbsp; posLeft = Math.floor(slotNumber/3), &nbsp; &nbsp; &nbsp; &nbsp; // the Modulus operator (%) is the remainder after division: &nbsp; &nbsp; &nbsp; &nbsp; // 0 1 2 0 1 2 0 1 2 .... &nbsp; &nbsp; &nbsp; &nbsp; posTop = slotNumber % 3; &nbsp; &nbsp; createObj("graphic", { &nbsp; &nbsp; &nbsp; &nbsp; name: soul[slotNumber].name, &nbsp; &nbsp; &nbsp; &nbsp; imgsrc: soul[slotNumber].slot , &nbsp; &nbsp; &nbsp; &nbsp; left:35+(70*posLeft), &nbsp; &nbsp; &nbsp; &nbsp; top:35+(70*posTop), &nbsp; &nbsp; &nbsp; &nbsp; width:70, &nbsp; &nbsp; &nbsp; &nbsp; height:70, &nbsp; &nbsp; &nbsp; &nbsp; pageid:page,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer:"objects", &nbsp; &nbsp; }); };
Very slick! Worked like a charm! I'm trying to build a little puzzle game and I anticipate needing to lean on the goodwill of this community quite heavily. &nbsp;Thank you for your quick and educative response. -Will
1450230125
The Aaron
Pro
API Scripter
No worries, lean all you like, we love helping! &nbsp;=D