The Godot Barn
Sign in
Sign in
Home
News & updates
Explore
Articles
Snippets
Shaders
Themes
Submit content
Sign in to submit content
Give or get help
Tutorials
Questions
Conversations
Coming soon!
GodotSteam Tutorials - Text Filtering
0
Description
"This tutorial covers adding text filtering in your game; specificially lobby chat, though it can be applied to things like usernames.\r\n\r\n??? guide \"Relevant GodotSteam classes and functions\"\r\n* [Utils class](https:\/\/godotsteam.com\/classes\/utils)\r\n\t* [filterText()](https:\/\/godotsteam.com\/classes\/utils#filtertext)\r\n\t* [initFilterText()](https:\/\/godotsteam.com\/classes\/utils#initfiltertext)\r\n???\r\n\r\n!!! warning Note\r\nYou may want to [double-check our Initialization tutorial](https:\/\/godotsteam.com\/tutorials\/initializing) to set up initialization and callbacks functionality if you haven't done so already.\r\n!!!\r\n\r\n## Preparations{.block}\r\n\r\nSince we are focusing on lobby chat, this tutorial will [piggyback off our lobby tutorial](https:\/\/godotsteam.com\/tutorials\/lobbies) and we will be making a [slight modification to the message callback](https:\/\/godotsteam.com\/tutorials\/lobbies#lobby-chat-messages) from that later on in this tutorial. First we will need to enable chat filtering in the Steam settings so we can properly test things are working.\r\n\r\nOpen your **Steam client settings** and navigate down to **Friends & Chat** then scroll down on the right until you see Chat Filtering and pressed the **Manage** button. Alternatively you can also just [open the **Community Content Preferences** by URL here.](https:\/\/store.steampowered.com\/account\/preferences#CommunityContentPreferences\/)\r\n\r\n\r\n\r\nOnce the account preferences loads, scroll down to the **Community Content Preferences** section and you should see **Chat Filtering**. For testing we will be changing the **Language Preferences** and **User Group Preferences**.\r\n\r\n\r\n\r\nHere we will set **Language Preferences** to **Filter strong profanity and slurs with \"\u2665\u2665\u2665\" or \"\\*\\*\\*\"** and untick **Do not filter text from my Steam Friends** in the **User Group Preferences**. This will make sure that if you are testing with friends, the proper filtering will be used. After we are done testing, you can switch these back to whatever you had previously.\r\n\r\nNow we should be ready to begin.\r\n\r\n## Initializing Filters{.block}\r\n\r\nInitialing the filters is very simple. You can place the function call pretty much anywhere but I would suggest [adding it to your **\\_on_lobby_joined** callback](https:\/\/godotsteam.com\/tutorials\/lobbies#joining-lobbies) if you are only using it for lobby chat filtering. Otherwise, you could [add it to your Steam initialization process](https:\/\/godotsteam.com\/tutorials\/initializing#initialize-steam) if you want to filter other texts than lobby chat.\r\n\r\n:::tabs\r\n@tab GodotSteam 4.20 and Newer\r\n```gdscript\r\nSteam.initFilterText()\r\n```\r\n\r\n@tab GodotSteam 4.19.1 and Older\r\n```gdscript\r\nSteam.initFilterText(0)\r\n```\r\n:::\r\n\r\nCurrently the default is 0 and currently no other filter options can be passed here yet. In GodotSteam 4.20, this parameter was removed since it is unnecessary but may be added in future versions if Valve enables it. It will need to be added in GodotSteam 4.19.1 or older.\r\n\r\nNow that we have initialized text filtering, we can actual clean up our texts!\r\n\r\n## Filtering Text{.block}\r\n\r\nWe have our filters set and filtering initialized so we will add one tiny bit of code to our lobby messages. Again, borrowing from our lobby tutorial, we will add the **filterText()** function in before displaying the incoming chat message:\r\n\r\n```gdscript\r\nfunc _on_lobby_message(lobby: int, user: int, chat_message: String, chat_type: Steam.ChatEntryType) -> void:\r\n\t# Make sure we are getting messages for the right lobby\r\n\tif lobby != Steamworks.lobby_id:\r\n\t\treturn\r\n\r\n\t# Make sure this is an actual chat message, filter it, then add it to our chat log stack\r\n\tif chat_type == Steam.ChatEntryType.CHAT_ENTRY_TYPE_CHAT_MSG:\r\n\t\tvar clean_message: String = Steam.filterText(Steam.TEXT_FILTERING_CONTEXT_CHAT, user, chat_message)\r\n\t\tchat_log.append_text(\"%s\\n\" % clean_message)\r\n```\r\n\r\nYou see above we are using the **TEXT_FILTERING_CONTEXT_CHAT** filtering context but there are [a handful of others you can use.](https:\/\/godotsteam.com\/classes\/utils#textfilteringcontext) The only other one I think would be useful is **TEXT_FILTERING_CONTEXT_NAME** which you can use to filter player or items names.\r\n\r\nA quick note: this will not filter text **you** send for yourself but other users, if their filtering is set correctly, will see \\*\\*\\* instead of any blocked words. Unfortunately, you will need to test this with another person or second Steam account to be sure it is working properly and even then it only works if the users have the appropriate settings enabled.\r\n\r\n!!! warning Encoding Breakage\r\nIn GodotSteam 4.19.1 and older, the **filterText()** function will break any special encoding, emojis, etc. so they will not render correctly. This is fixed in GodotSteam 4.20 and newer.\r\n!!!\r\n\r\nAnd that is it for our text filtering tutorial!\r\n\r\n## Additional Resources{.block}\r\n\r\n### Example Project\r\n\r\n[You can view this tutorial in action with more in-depth information by checking out our upcoming free-to-play game Skillet on Codeberg.](https:\/\/codeberg.org\/godotsteam\/skillet) This link will take you to the direct file where this tutorial comes from but feel free to explore the rest of the project too!"
Comments
Log in to post a comment
Licensed under the CC-BY license
See the full license details
Submitted by
Gramps
Table of contents
Compatibility
Works in Godot
3.x / 4.x
Tags
GodotSteam
SteamĀ®
steamworks
text filtering
Share this tutorial
Share on Bluesky
Share on X / Twitter
or share this direct link:
https://thegodotbarn.com/contributions/tutorial/903/godotsteam-tutorials-text-filtering
Please wait ...
Okay
Okay
No
Yes
Okay