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

Problem with rollable table

Hello, I'm using a Rollable Table in my script that automates combat. There is a point where, once the attacker hits his target, I have to check where the blow lands. I created a locations table (calles locs) with 10 items in it. It works pretty well, but when I call it within the script, the code following the function is executed before the sendChat returns. My function is sendChat(attackerName, "/roll 1t[locs]", function(ops) { var rollresult = JSON.parse(ops[0].content); loc = rollresult.rolls[0].results[0]; }); And straight after that I need to use the loc variable (that is initialized outside). Unfortunately it seems that the code following the sendChat uses the variable BEFORE the sendChat function has done its job. Logging inside and outside it, in the scripts log I can see the log outside the function before the one inside it. Any hints? Thanks
I have to say that I really like the idea of being able to pinpoint where a blow lands on a character. I can't say I know anything about coding, but would it work better by making a "character sheet" that contains the locations? If you end up getting this up and running I'd love to implement it in my own game.
I use a Rollable Table for the locations because my players need to roll on it from time to time. It is quicker and basically... is one of the purposes of a Rollable Table. Moreover, We use the HERO System rules where you decide where a blow lands using 3d6. In a Rollable Table is as simple as putting the right weight for each item in order to have the same bell curve. For called shots where they can choose a location, I use an array in my scripts where I simply "duplicate" the contents of a rollable table (imagewise) and the location is the index of the array. For example, in my rollable table the head is "0", the hands are "1" and so on. My array starts like this: aLocsModifier[0] = [8,"<a href="https://s3.amazonaws.com/files.staging.d20.io/images/150503/Rl95xiAD4-fJ5Y8d6jDieg/med.gif?1384730029" rel="nofollow">https://s3.amazonaws.com/files.staging.d20.io/images/150503/Rl95xiAD4-fJ5Y8d6jDieg/med.gif?1384730029</a>"]; so the index for that entry is "0" (head). The other two values are the to-hit modifier and the link to the image representing the location. When they choose to hit the head, my script gets the array item with index 0 (in case they hit it in spite of the huge -8 modifier, that is). You can also use a character sheet to store location names and modifier of course. There are many ways to obtain the same results
By the way, I solved the problem putting all the code that followed the call of the Rollable Table in a function that is called inside it. But I'd really like to know if there is a reason for this "asyncronous" behaviour of the code. Fabio
1386129543

Edited 1386129570
Lithl
Pro
Sheet Author
API Scripter
Fabio M. said: I'd really like to know if there is a reason for this "asyncronous" behaviour of the code. sendChat (and therefore the optional third argument to sendChat) is asynchronous. This can be seen with an API command that spits out text to the chat window, and creating a macro which calls that command several times -- the output is not guaranteed to be in the input order. As for why sendChat is asynchronous , I assume it's to do with keeping players and the firehost server up to date with one another.
Yep, it makes sense. Thanks for the answer.
Learn something new every day, it seems. Thanks for taking the time to explain that Fabio. Also, I'm happy to see that you got it working :)