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

Pass object array into string while retaining objects?

1539181661
Missingquery
Pro
Sheet Author
API Scripter
I am working on a simple script that will take a "snapshot" of all of the attributes within a given campaign and make it so that you can reset all of the attributes back to that point later- essentially, savestates within Roll20. Here is my script as it stands: on('chat:message', function(msg) { if (msg.type != 'api') return; var parts = msg.content.split(' '); var command = parts.shift().substring(1); var objs = []; var objstates = []; var divstyle = 'style="width: 189px; border: 1px solid #353535; background-color: #f3f3f3; padding: 5px; color: #353535;"' var tablestyle = 'style="text-align:center; margin: 0 auto; border-collapse: collapse; margin-top: 5px; border-radius: 2px"'; var headstyle = 'style="color: #f3f3f3; font-size: 18px; text-align: left; font-variant: small-caps; background-color: #353535; padding: 4px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;"'; var namestyle = 'style="background-color: #353535; color: #f3f3f3; text-align: center; font-weight: bold; overflow: hidden; margin: 4px; margin-right: 0px; border-radius: 10px; font-family: Helvetica, Arial, sans-serif;"' var wrapperstyle = 'style="display: inline-block; padding:2px;"' var statdiv = 'style="border: 1px solid #353535; border-radius: 5px; overflow: hidden; text-align: center; display: inline-block; margin-left: 4px;"' var cellabel = 'style="background-color: #353535; color: #f3f3f3; font-weight: bold; padding: 2px;"' //save if (command == 'savestate') { //grab objs objs = findObjs({type: "attribute"}); log(objs) //grab obj states for (var i in objs){ objstates[i] = objs[i].get("current") } sendChat("System", '/w gm <div ' + divstyle + '>' + //-- '<div ' + headstyle + '>Mystery</div>' + //-- '<div style = "margin: 0 auto; width: 80%; margin-top: 4px;">' + //-- '<p style = "margin-bottom: 0px;"> State saved! </p>' + //-- '</div>' + //-- '</div>' + //-- "[Load state](!&#"+"13;!loadstate " + objs + objstates + ")" ); } if (command == 'loadstate') { log("States gotten!") } }); My problem is that the actual array for objects always gets converted into [Object object], which doesn't work at all when I'm trying to get the actual objects once the second command is typed in. Is there some way to pass in the objs array to the command button while still retaining all of the individual objects within?
1539183206
Jakob
Sheet Author
API Scripter
You should really use semicolons. Anyway, as far as I can see, you want to put the information about all the attribute objects in the campaign at the current point in time into the content of an API command button ??? Don't do that. Seriously, don't.  That's far too much text in a campaign of any significant size - which will have thousands of objects. You can think about storing all this information into a variable in the API instead, give it some kind of ID, and then let the command button contain the ID. That's a much  saner solution.
I agree. Don't put that evil in chat. Maybe instead, if you're set on doing it, store it in a handout. Never open the handout. Date a couple of them and you can load by passing in the name of the handout. "!loadstate State-10-10-18-10-36" or something. No idea on performance but it should be better than putting it in chat. Should persist between sessions. I have only 9 characters in my game and 15k attributes. That's like 3.5 million characters in JSON.stringify which is easily 6MB of pure text. Putting that in chat just once is likely to bring every person connected to the game down. There's hopefully a character limit to sendChat, regardless.
1539222095
The Aaron
Pro
API Scripter
I third the not dumping to chat.&nbsp; I actually have a script that writes ~1mb messages to chat (ImperialCalendar), you don't really want to go there. =D I agree with Noon, storing that on an archived Handout is ideal.&nbsp; You can use the name for an identifier like "[Snapshot]: 2018-10-10 21:40:00" and then store the data in the handout.&nbsp; I'd recommend using my Base64 script to encode and decode the data so as not to have it accidentally tweaked:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/Base64/Base64.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Base64/Base64.js</a> You can then have a !snapshots command that finds all the handouts that begin with [Snapshot] and outputs buttons that use their id to do the actual restore.