Dynamic List of Users, appending an array/list?

I’m trying to use night bot to create a list of users within itself so i can call upon those names for other logic, I think I should be able to do it all with one command.

The way i was thinking of is something like !kiss $(eval var query1 = $(1); var query2= $(2); array friends = []; bool friend = 0; if query1 == “add” then friends.append(query2); else (while i < friends.length, i = 0, do; if query1 == friends(i) then “the biggest kisses”; friend = 1; else i += 1;) if friend = 0 then “mwah”

i don’t suppose there would be a dynamic way to keep a list like that within a command is there, so would i need to hardcode the usernames in there? if any of the logic isn’t clear i can explain it but it should be pretty straight forward, idk about the syntax of everything because i haven’t really used this language before

Hey @senti3ntb3ing!

Yeah, JavaScript doesn’t work this way, it’s much more flexible than many other languages, which present advantages, but also can introduce errors, haha! And for Nightbot we simplify things quite a lot to save space.

There’s indeed no way for Nightbot to “remember” the list from one command call to another: once the response is sent, everything is purged, so you’ll have to hardcode some usernames.

I tried translating your code into JS, but it doesn’t make much sense, I don’t think it’d work as you expect it, the easiest solution would be to describe what you want.

1 Like

okay, so basically what im trying to do with the code is have this command, !kiss, give one response for a standard user, but if their username falls within a list of usernames i’d set, then it would give a different response. I’ve done this before with just a singular user, but I’ve never tried to have a list or do a multiple compare with JS, so any syntax I try to come up with is going to be wrong.

So i guess the real issue that I’m having right now since you clarified that theres no way for Nightbot to remember code changes from one query to the next, is 1) How to create the list of (User1, User2,…), and then how to properly compare $(user) to said list.

I see, well, usually for such commands we create an array of users and then we look if the user is in it, like this:

a=['USER_1', 'USER_2', 'USER_3', ... , 'USER_N']; for(i=0; i<a.length; i++){if('$(user)'==a[i]){}else{}}

Hopefully that helps, otherwise I’ll write the full command for you.

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