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] Interacting with external sources?

Hi! I'm trying to make a script for when I stream so that it switches avatars for my players when they below 50% health and when they go unconscious. I've researched solutions, but I can't seem to find any way to interact my scripts with Roll20. Does anyone else in here have any ideas?
1482079173
The Aaron
Pro
API Scripter
Are you talking about the player's Avatars, the character Avatars, or the Token image?   The first isn't possible, the second two are only possible if the image is in a user library. 
The Aaron said: Are you talking about the player's Avatars, the character Avatars, or the Token image?   The first isn't possible, the second two are only possible if the image is in a user library.  I'm talking about their tokens on the board and the character sheet that the tokens represent. My initial idea was to use the API to check if their tokens have changed health and if it's below a certain threshold I would try to connect to my python script though a publicly hosted JSON.
1482084607

Edited 1482084658
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The API can only interact with Roll20 objects ( and only specific ones at that ). Interacting with your python script isn't possible. I'm not sure why you'd need to for what you want to do though as, from what I understand, everything you want to react to and affect is in Roll20.
1482085370

Edited 1482085484
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, actually, there may be a way to interact with the python script in a roundabout way using the external journal. You'd have your Roll20 API script save things to each character's GMNotes and then have your python script pull it out from the external journal (from the brief investigation I did, it looks like the external journal updates whenever the in game journal does, no refresh necessary). I don't know python, and I am no where near the scriptomancer that Aaron "Arcane Scriptomancer" is, but it might be possible.
Ah, that actually sounds like it could work! All I need is the player's HP and updating some images based on that, so cheers! I'll investigate further.
I believe the stranger part is probably that the API spits out this when I try to access my handout: [{"name":"Player_Healths","notes":1482087186227,"gmnotes":1482089083643,"inplayerjournals":"","archived":false,"controlledby":"","_type":"handout","_id":"-KZIG2NanuAUElImV1Iu","avatar":""}] While my handout's notes actually contains: {"Alta":{"maxhp":62,"hp":62},"Leo":{"maxhp":64,"hp":64},"Neltharion":{"maxhp":98,"hp":98},"Tempeste":{"maxhp":59,"hp":59}} If I try to log(PlayerHealths['notes']), it gives me undefined. What gives?
1482091330

Edited 1482091350
Jakob
Sheet Author
API Scripter
See  Wiki . The notes or gmnotes fields cannot be accessed synchronously, you need to use PlayerHealtsh.get() with a callback function.
Jakob said: See  Wiki . The notes or gmnotes fields cannot be accessed synchronously, you need to use PlayerHealtsh.get() with a callback function. Ah, cheers! That does make sense, but even then: var PlayerHealths = findObjs({ _type: "handout", name: "PlayerHealths" })                      PlayerHealths.get("notes", function(notes) { log(notes); }); Throws a TypeError: TypeError: PlayerHealths.get is not a function It seems to do the same thing with character objects, but not token objects?
1482091921

Edited 1482091952
Jakob
Sheet Author
API Scripter
findObjs returns an array  of all found objects, not just one object, so you would want var PlayerHealths = findObjs({ _type: "handout", name: "PlayerHealths" })[0] This should happen no matter the type of object you are searching for.
Jakob said: findObjs returns an array  of all found objects, not just one object, so you would want var PlayerHealths = findObjs({ _type: "handout", name: "PlayerHealths" })[0] This should happen no matter the type of object you are searching for. Eureka! Thank you very much! The handout updates when the players' health gets altered, now I should be able to access the HTML on the handout's web page with a small python script and hook that up to Open Broadcaster Software. Cheers again!
1482094681
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You'll want to make sure that updating the sheet via API triggers the external journal to update
Scott C. said: You'll want to make sure that updating the sheet via API triggers the external journal to update It does, in fact :) 
1482101047

Edited 1482101065
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Good, somethings the API doesn't update till a reload/reopen.
Huh, interesting. So you're going to be using this to update the character hp in real time for streaming?
SkyCaptainXIII said: Huh, interesting. So you're going to be using this to update the character hp in real time for streaming? Yup, display HP and also switch images of player portraits to red/grayed out depending if they are below 50% or at 0% hp. I'm still investigating how I would read the page since it's private.
Wasp said: SkyCaptainXIII said: Huh, interesting. So you're going to be using this to update the character hp in real time for streaming? Yup, display HP and also switch images of player portraits to red/grayed out depending if they are below 50% or at 0% hp. I'm still investigating how I would read the page since it's private. Under campaign settings or something, maybe game settings, you can set your journals to public.
SkyCaptainXIII said: Wasp said: SkyCaptainXIII said: Huh, interesting. So you're going to be using this to update the character hp in real time for streaming? Yup, display HP and also switch images of player portraits to red/grayed out depending if they are below 50% or at 0% hp. I'm still investigating how I would read the page since it's private. Under campaign settings or something, maybe game settings, you can set your journals to public. Indeed, that worked! I've successfully integrated to Webdriver and Roll20 to read the JSON from it: (See Alta's HP) This is after I edited the token's HP bar, and also changed the HP in the character sheet. Now I just need to update a text file to display HP in Open Broadcaster Software.
1482180300

Edited 1482180989
Aye, through Python I have now made it work: <a href="https://www.youtube.com/watch?v=-cOJBy7z79I" rel="nofollow">https://www.youtube.com/watch?v=-cOJBy7z79I</a> You will need Python 3.x,&nbsp;Selenium, and ChromeDriver to make this script work: <a href="https://www.mediafire.com/?th78s8bha9ob1wa" rel="nofollow">https://www.mediafire.com/?th78s8bha9ob1wa</a> Run it in a separate folder as it will create individual text files for each of your players' HP and MaxHP. I'm in the process of ironing out issues in the Roll20 script and will upload this shortly.
1482180709
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Very cool. Now if we ever get externally updatable journals, you could also maybe have this go the other way.
Scott C. said: Very cool. Now if we ever get externally updatable journals, you could also maybe have this go the other way. Good idea, I'd have to find the sheet by the character name and update the HP and MaxHP attributes, no?
1482181140
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Wasp said: Scott C. said: Very cool. Now if we ever get externally updatable journals, you could also maybe have this go the other way. Good idea, I'd have to find the sheet by the character name and update the HP and MaxHP attributes, no? Looks like the external journal is indexed by handout/character id, so you'd probably have to figure out some way to work with that. Also, probably won't be possible for a while. I don't think there's been any movement on improved external journal usability for a while.
Scott C. said: Wasp said: Scott C. said: Very cool. Now if we ever get externally updatable journals, you could also maybe have this go the other way. Good idea, I'd have to find the sheet by the character name and update the HP and MaxHP attributes, no? Looks like the external journal is indexed by handout/character id, so you'd probably have to figure out some way to work with that. Also, probably won't be possible for a while. I don't think there's been any movement on improved external journal usability for a while. At the moment, my script only works one way (from character sheet and token updates to the handout). I would probably have to save the external inputs in the GM notes, which then updates the tokens and subsequently the 'normal' Notes on the handout.