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

[REQUEST and/or HELP] Backwards

1569935238
Finderski
Pro
Sheet Author
Compendium Curator
Looking for a Script that would reverse everything sent to the Chat window except for things in a Roll Template if the reverse is enabled and just send everything normal if it's disabled. How difficult would something like that be to make?  What would be even cooler is if the letters were actually reversed as well... From what I've gathered, it should be pretty simple...just need to use something like: str.split("").reverse().join(""); It's the enabling/disabling and watching for roll templates (and probably other standard things like whispering to the GM) that I'm struggingling with figuring out...
1569982631

Edited 1569982663
Finderski
Pro
Sheet Author
Compendium Curator
Ok, I'm so not proficient with Javascript and barely know enough to stumble my way through a Sheet Worker...but despite that, I figured I'd see what I can figure out.  Here's what I did (and it doesn't work...): var Backward = Backward || (function() { 'use strict'; state.backwardapi = {doReverse: false}; var version = 0.1, HandleInput = function(msg) { var args, text; if (msg.type !== "api") { log("Not an API..."); if(msg.type === "general" && state.backwardapi.doReverse === false) { log("In the if statement: doReverse is false"); sendChat(msg.who,msg.content + " and I appended this..."); return; } else { log("Made it to the else statement: doReverse is true"); msg.content = msg.content.split("").reverse().join(""); //sendChat(msg.who,msg.content); return; } } args = msg.content.split(" "); switch(args[0]) { case '!backward': if(args.length !== 2 && (args[1] !== 'on' || args[1] !== 'off')) { sendChat(msg.who,'Too many, too few, or wrong type of input. !backward should have a declaration of "on" or "off".'); break; } else { if(args[1] === "on") { state.backwardapi.doReverse = true; } else { state.backwardapi.doReverse = false; } (state.backwardapi.doReverse === true ? log("Backward enabled...") : log("Backward disabled...")); //sendChat(msg.who,text); break; } } }, RegisterEventHandlers = function() { on('chat:message', HandleInput); }; return { RegisterEventHandlers: RegisterEventHandlers }; }()); on("ready",function() { 'use strict'; Backward.RegisterEventHandlers(); }); It doesn't intercept the message and prevent it from playing, which is why I think it ends up in a loop...it displays the message, the script sees that, takes it and puts it out in chat again, which then sees it, grabs it, puts it out in the chat again, ad infinitum...so, my approach for this is a failure (so far).  What I have learned: 1. I know how to use the state to store whether I backward is enabled or disabled. 2. I have no idea what I'm doing...LOL 3. I know there are different types of messages, and if I alter just type === "general" that should be sufficient. Now, I just need to figure out how to get it not get stuck in that inadvertent loop. Any pointers/idea?
1569984542
The Aaron
Forum Champion
API Scripter
To avoid the loop, look at the msg.playerid. If it's "api" don't process it, you ( probably ) sent it. Another way would be to store the last couple things you sent and check if what you're getting us what you sent, but that's a bit more complicated.  The API is reactive, it can only react to events that have already happened, and provide future events. When someone sends a message to chat, it has already happened, so the api can only react to it, not prevent it. Even API chat commands have fully been processed in the chat system before the API knows about them, they just happen to have no output, so nobody sees them. If you want to control the output, the input must be an API command. 
1569984752
The Aaron
Forum Champion
API Scripter
There's a bug with your state use. Basically, you trash your state each time the API starts. You should check to see if your property in the state exists and only create your state object if it doesn't. Somebody (wonder who! =D) wrote some pretty detailed instruction on proper state usage here:&nbsp; <a href="https://wiki.roll20.net/API:Objects#state" rel="nofollow">https://wiki.roll20.net/API:Objects#state</a>
1569986152
Finderski
Pro
Sheet Author
Compendium Curator
Cool...I was afraid that was going to be the case. :( Thanks for your help. &nbsp;BTW - that script is based on one you helped me with waaaaaaay back in the day. LOL
1569986207
Finderski
Pro
Sheet Author
Compendium Curator
The Aaron said: There's a bug with your state use. Basically, you trash your state each time the API starts. You should check to see if your property in the state exists and only create your state object if it doesn't. Somebody (wonder who! =D) wrote some pretty detailed instruction on proper state usage here:&nbsp; <a href="https://wiki.roll20.net/API:Objects#state" rel="nofollow">https://wiki.roll20.net/API:Objects#state</a> Cool. &nbsp;I'll check it out. &nbsp;Thanks. :)
1570017393
The Aaron
Forum Champion
API Scripter
Yeah, I recognized the style. =D No problem, I'm happy to help!