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] Can't seem to get my damage application section to work.

I have been working on this, off and on, all night. Thanks to Brian for the initial help with the hump. I am in the home stretch! <a href="https://gist.github.com/anonymous/6c3f70770561bbe5df08" rel="nofollow">https://gist.github.com/anonymous/6c3f70770561bbe5df08</a> At the bottom of the script (everything else has been testing and debugged), lines 57-65 is where the damage application starts. It looks fine to me but when I run the script I get this " TypeError: Object Orc-Warrior has no method 'get' at evalmachine.&lt;anonymous&gt;:58:25 at eval (" Am I missing something here? Like I said, it looks solid to me, but I am but a novice; chaff upon the wind compare to many of you.
1400166183

Edited 1400166241
Riley D.
Roll20 Team
So you're setting whoTarg on line 18, it's just a string back then, "Orc-Warrior" (in this example, but it would change based on what you're inputting). You need to take that string and actually get the corresponding object to do stuff with it. Orc-Warrior is a "name", but you need the actual "monster" if that makes sense. You could do something like: var targetObj; var tokenPossibles = findObjs({_type: "graphic", name: whoTarg}); if(tokenPossibles.length &gt; 0) { targetObj = tokenPossibles[0]; } else { log("Error: couldn't find a token with the name: " + whoTarg); return; } //Then change all your .get() and .set() calls later on to use targetObj instead of whoTarg... However, another alternative, and perhaps a better one depending on your specific use case, would be to take advantage of the select information sent to the API in the msg object. If your players will select the object before doing the API call, you could do: var targetObj; if(msg.selected && msg.selected.length &gt; 0) { targetObj = getObj(msg.selected[0]._type, msg.selected[0]._id); } if(!targetObj) { log("Error finding the object you selected."); //this really shouldn't happen return; } //Again, change your later calls to use targetObj instead of whoTarg Anyway, those are two possibilities. Hope that helps! (Note that I didn't actually run either of those snippets through the API console, so there may be a typo, just let me know if it doesn't work for some reason).
Both the selected token (token attacking) and the target token are being passed to the script via macro. The macro looks like this... !attack @{selected|token_id} @{target|token_id} @{target|Armor} @{selected|BaseHit} @{selected|BonusDamage} @{selected|token_name} @{selected|WeaponDamage} @{target|token_name} @{target|HP} line 12 is where I am setting the token_id as targetID. I added token_name later for convince of getting the names for the emote calls. Would the IDs not be a direct reference to the monsters token, or am I miss interpreting your meaning of "needing the actual 'monster'?" You know, Brian was helping me on this, and he had a portion that was trying to get the IDs as graphics. I think I need to revive that portion of the code.
Yep you can pass the type and ID directly into getObj and accomplish the same thing.
1400207361
Lithl
Pro
Sheet Author
API Scripter
Michael P. said: You know, Brian was helping me on this, and he had a portion that was trying to get the IDs as graphics. I think I need to revive that portion of the code. The type for token objects is "graphic."
Thanks guys.
1400313566

Edited 1400315354
Ok, I finally got it to work using the first option Riley. However, there now seems to be a problem with line 57 not triggering the else statement body of lines 63 to 65. The bar3_value just goes into the negative rather then applying the "status_dead" maker. First it was using != 0 (which is saying 'not equals 0' correct?) and I decided that since it can a negative value that I would restructure the if/else statement to if (targetObj.get("bar3_value") &lt;= 0) then (do the code of lines 63 through 65) else (do damage code of line 59) Shouldn't the script see that the value of "bar3_value" as being 0 or lower then doing the the status check (which should be false since it had positive HP until now) and then add the "status_dead" marker? I have even tried making it read &lt;= 1 as without any results I want to see. Be advised that I have changed the code in this lines has changed to reflect the change of whoTarg to targetObj since adding the graphic get function.
1400337466

Edited 1400337754
I just can get this to work. I have been trying and no matter what I do, I can not get the script to targetObj.set("status_dead", true) to trigger. The script just ignores the if(currentHP &lt;=0) statement and just go to the else. I don't see what I am missing here? does the if statement need to use the full targetObj.get("bar3_value") rather then use the variable?
I got through this. Yes, the script wasn't working using the variable call... also the line currentHP = targetObj.set("bar3_value", parseInt(targetObj.get("bar3_value")) = 0); should just be currentHP = targetObj.set("bar3_value", = 0); since is a straight set and not a calculation. Thank you guys for getting me through this and taking the time to help me and being patient with me while I learn the API. Now that I have a basic auto-resolve, time to flesh it out so I can get call it for either melee or ranged... oh boy, here we go again!