Game Conditional Based Command

Asked Aug 9, 2021·3 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

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...

$(eval
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';
if(r)
'"{{game}}": ' + r + '.';
else
'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

3 replies

Hey @Glad Moose!

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:

$(eval
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 https://pastebin.com/raw/XXXXXXXX);

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 https://pastebin.com/raw/XXXXXXXX);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 ^-^