DevLog 20: Twitch integration in Death and Taxes
Hello peeps!
Oak here! As chief shitposter and coder extraordinaire, I'd like to talk to you a little bit about Twitch integration. I implemented a way for Twitch streamers to interact with their audiences in Death and Taxes, which involves a few checkboxes and a really neat little book.
QUICK REMINDER. We're going to be launching IN A MONTH (less than 30 days), so if you haven't followed us here on itch already, or haven't wishlisted us on Steam yet, do so now! Then you'll get notified when we release :3
You can conveniently enable it in the Options menu!
After that you can click on the book to vote! And when that's done, viewers can post messages in the chat to express their desire.
We thought it'd be a fun way to just give content creators a chance to bring their audience into the game with them. All of this is completely optional, of course. This feature was something that we had been discussing mostly "as a joke" last summer, but the more we talked about it the more sense it made. Eventually, we laid down some facts on how we could use it, prototyped it, did some very basic UX design for it, and then Leene produced dedicated art assets to give it a polished and in-world look. We didn't want to sacrifice immersion for the sake of having a "gimmick" (so to speak). We're quite pedantic when it comes to worldbuilding, and I think in this case it played out in our favour.
So how did we actually do this?
Luckily, it's quite simple and only takes VERY limited coding knowledge, so basically anyone could do it! Our engine of choice for Death and Taxes has been Unity, and we're running on the 2019.2.10f1 version. It's not the latest, but it's stable enough for our needs.
The steps you need to take to set everything up, if you're using Unity:
- Go to https://github.com/TwitchLib/TwitchLib.Unity and download the DLL there, the latest on at time of writing is 1.0.0: https://github.com/TwitchLib/TwitchLib.Unity/releases/tag/1.0.0 (TwitchLib.Unity.dll)
- Import the DLL into your Unity project (literally just drop it somewhere in your Plugins folder)
- Set up Twitch credentials so that you'd have a bot who does all the heavy lifting for you (reading chat messages, essentially)
- Create a class that manages your Twitch connection
- That's it.
This list seems short, and that's because it's quite simple to do. You can set all of this up within hours. The longest time it took for me at any single point was the third, as I was waiting for a verification e-mail from Twitch for about 20 minutes. Other than that, it was super fast. All you really have to do, is follow IMPORTANT ----> this guide <----- IMPORTANT and you'll be golden. The most important place where you really have to pay attention to what you're doing is the "SETTING THINGS UP" chapter. Just follow the guide line-by-line and you will be fine. I won't transcribe or re-iterate on what the guide does. Seriously, it's one of the best guides I've read. It really takes you through everything step-by-step.
You can do a lot of neat things with the library, but our design needed something very barebones. We just needed our bot to read the chat messages and search for the phrases that would count as a vote. To that end, I merely had to register to a message handler, which the library provides, which looks something like this:
private void ClientReference_OnMessageReceived(object sender, TwitchLib.Client.Events.OnMessageReceivedArgs e) { Debug.Log("Sender: " + sender + "; " + e.ChatMessage.Username + " wrote: " + e.ChatMessage.Message + " is broadcaster: " + e.ChatMessage.IsBroadcaster); if(VoteCounter.instance.IsVoteInProgress()) { if(e.ChatMessage.Message.ToLower().Contains(SaveManager.instance.CurrentOptions.StreamCommandDie.ToLower())) { VoteCounter.instance.RegisterVote(e.ChatMessage.Username, true); } if (e.ChatMessage.Message.ToLower().Contains(SaveManager.instance.CurrentOptions.StreamCommandLive.ToLower())) { VoteCounter.instance.RegisterVote(e.ChatMessage.Username, false); } } }
I have a very simple algorithm that the code is supposed to be doing:
- Check if a vote is in progress (clicking on the book starts a vote)
- Check whether the message contains the phrase that counts as a vote (which can be customized in the options menu) - and yes, I do realize that if you'd write both phrases into a single message then sparing someone would take the vote, but I'm writing code for cool people, not for trolls
- If there is a "vote phrase" in the message, register the vote
- If a vote by an user was already registered, replace it with the new vote (no multi-voting so spamming won't work)
- Update the visuals!
public void RegisterVote(string username, bool die) { if (UserVoteMap.ContainsKey(username)) { if (UserVoteMap[username]) { DieVotes--; } else { LiveVotes--; } UserVoteMap[username] = die; if (UserVoteMap[username]) { DieVotes++; } else { LiveVotes++; } } else { UserVoteMap.Add(username, die); TotalVotes++; if (die) { DieVotes++; } else { LiveVotes++; } } float liveRatio = (float)LiveVotes / TotalVotes; float dieRatio = (float)DieVotes / TotalVotes; Debug.Log("liveRatio: " + liveRatio); Debug.Log("dieRatio: " + dieRatio); Debug.Log("livePercent: " + Mathf.RoundToInt(liveRatio * 100.0f)); Debug.Log("diePercent: " + Mathf.RoundToInt(dieRatio * 100.0f)); SetScaleTargetAngle(Mathf.Lerp(-35, 35, dieRatio)); TextLivePercentage.text = Mathf.RoundToInt(liveRatio * 100.0f) + "%"; TextDiePercentage.text = Mathf.RoundToInt(dieRatio * 100.0f) + "%"; }
This is just scratching the surface of what you could do with this library. Fortunately or unfortunately, Death and Taxes does not really have many points of interaction for community engagement in the game, other than the main mechanic. Implementing all of this took me about an hour, with around 15 minutes of testing on top. At first, I didn't have the voting phrases customizable, but I asked our streamer friends on Twitter and they said it'd be a nice thing to have. Adding that on top took me another hour, with additional testing and user input validation.
On top of that, using this kind of library is safe. You can also program the bot to send messages to the chat, but I left that out, as some streamers would have to grant the bot extra privileges to write to chat, plus there is no real need for it, as the streamer can call out the vote on-stream and also there is a visual indicator on the screen (the red book).
Just make sure you come up with secure credentials for your bot and enable two-factor authentication. You don't want to be losing accounts.
In action, all of it looks something like this:
Many thanks to the creators of TwitchLib, and Honest Dan Games for the awesome guide on how to get started with it! I hope that if you're ever making a game yourself, you found inspiration on how quickly you can add a neat little feature to share the fun!
And as always, thank you everyone for reading along! I hope you all have a wonderful day :)
Much love!
Death and Taxes <3
PS: *Release anxiety intensifies*
Get Death and Taxes
Death and Taxes
You are the Grim Reaper on an office job. Save the world.. or condemn it to damnation?
Status | Released |
Author | Placeholder Gameworks |
Genre | Simulation, Visual Novel |
Tags | 2D, Atmospheric, Dark Humor, death, Meaningful Choices, Narrative, Story Rich, watercolor, weird |
Languages | English |
Accessibility | Color-blind friendly |
More posts
- Hats & SpanishJul 30, 2024
- Death and Taxes: Now in More Languages than Before <_<Mar 17, 2023
- Released a free Death and Taxes Coloring Book! (download here)Mar 18, 2022
- Death and Taxes @ IWOCon 2021!Mar 28, 2021
- Death and Taxes Anniversary FATE BODY PILLOW Raffle!Feb 16, 2021
- First Anniversary and Brazilian Portugese localization release!Feb 15, 2021
- Death and Taxes - Best Estonian Game of 2020!Jan 18, 2021
- Halloween Update Update and Winter Sale!Dec 23, 2020
- Death and Taxes in Top 100 for IndieDB Indie of the Year!Dec 11, 2020
- WHAT IS HAPPENINGNov 26, 2020
Comments
Log in with itch.io to leave a comment.
ah no way, i didnt know you guys had twitch integration
i wonder how many people on twitch didnt know that either??
There are quite a few who have used it already!