Game Conditional Based Command

Hi all,

I am trying to make a command that will automatically change the response based on the game I am playing. I want to use this as I play a few FPS games where my sensitivity differs and many users come in and ask when settings I use.

I want to create a !sens command which when playing Splitgate will display Splitgate: 800 DPI | 4.0 Sens (Horizontal/Vertical) | 0.8 Zoom Multiplier and when playing Valorant it will display VALORANT: 800 DPI | 0.5 Sens.

This is what I have so far…


var r = false;    

if('$(codeOCE "{{game}}")' == 'Splitgate')        
r = '800 DPI | 4.0 Sens (Horizontal/Vertical) | 0.8 Zoom Multiplier';    

else if('$(codeOCE "{{game}}")' == 'VALORANT')        
r = '800 DPI | 0.5 Sens';    

'"{{game}}": ' + r + '.'; 

 'No sens information available.';  


However, this seems to always give me a response of “No sens information available.”

I believe that I have seen some similar posts out there but none of them seem to work when I try to add them to my command list.

Thank you ^-^ <3

Hey @codeoce!

That’s because $(codeOCE) is not a variable, but your channel name, if you read the documentation on $(twitch) it doesn’t say to replace twitch with your username, the correct syntax is: $(twitch username "text") and you can use $(channel) instead of username: $(twitch $(channel) "text").

With that in mind, you can get the game by using $(twitch $(channel) "{{game}}"), and since you repeat that line a couple time throughout the code you can simplify it, the goal is to not repeat yourself:

  let output = 'No sens information available';
  const currentGame = '$(twitch $(channel) "{{game}}")';
  const games = [
      'title': 'Splitgate', 
      'dpi': '800 DPI | 4.0 Sens (Horizontal/Vertical) | 0.8 Zoom Multiplier'
      'title': 'VALORANT', 
      'dpi': '800 DPI | 0.5 Sens'
  for (let i = 0; i < games.length; i += 1) {
    if (currentGame === games[i].title) {
      output = games[i].title + ': ' + games[i].dpi;
  output + '.';

Notice how I used an array with objects inside it to store all your game information, that’s to have a better overview of your data. After adding some more game entries you’ll lack space, in which case I advise using Pastebin: create a paste, set it to never expire and to be unlisted, and create a JSON following the same syntax as I did inside of it (reminder that JSON only works with double quotes "), after that, to access it in the command use $(urlfetch):

const games = $(urlfetch json;

There you have it, now to minify the code I gave above:

$(eval o='No sens information available';t='$(twitch $(channel) "{{game}}")';g=[{'n':'Splitgate','dpi':'800 DPI | 4.0 Sens (Horizontal/Vertical) | 0.8 Zoom Multiplier'},{'n':'VALORANT','dpi':'800 DPI | 0.5 Sens'}];for(i=0;i<g.length;i++){if(t==g[i].n){o=g[i].n+': '+g[i].dpi;}}o+'.';)

Or with the JSON:

$(eval o='No sens information available';t='$(twitch $(channel) "{{game}}")';g=$(urlfetch json;for(i=0;i<g.length;i++){if(t==g[i].n){o=g[i].n+': '+g[i].dpi;}}o+'.';)

Note: I replaced title with n in the objects.


Thank you so much. Now that I have read your code it makes so much sense and I understand it. Thank you for your help ^-^


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.