mIRC Homepage
Good evening everyone.
I've been making a twitch bot for a streamer and I've been successful getting values and all those stuff from apis but now I have a doubt.
The bot get some values from the api as follows:
Code:
var %i = 1
while (%i < 7) {
  SET %slot.%i = <json parser stuff here>)
  inc %i    
}

So this gives me 6 variables.

Imagining that this sets..
Code:
slot.1 = A
slot.2 = A
slot.3 = B
slot.4 = C
slot.5 = C
slot.6 = C

How can I make it so that my bot says that there are two A's, one B and three C's in an efficient way?
(or even more different values like one of each [a,b,c,d,e,f] p.e.)

Thanks in advance
Use dynamic variable.
Note that /set doesn't use the '=' equal sign, assuming you have the variable set correctly:

Code:
var %i = 1
while ($var(slot.*,%i) != $null) {
  inc %nbrof. $+ $var(slot.*,%i).value
  inc %i    
}
%i = 1
while ($var(nbrof.*,%i) != $null) {
echo -a $gettok($v1,2,46) appeared $var(nbrof.*,%i).value time(s)
inc %i
}
Hi, thanks for your reply.
By some reason, it is only counting the last variable value.

Code:
Slot 1: A
Slot 2: A
Slot 3: A
Slot 4: A
Slot 5: A
Slot 6: A
Slot 7: A
Slot 8: A
Slot 9: B
B appeared 1 time(s)


And there was a typo in %i = i, changed to %i = 1 as it was a never ending loop that crashed mIRC.
If you could help me by fixing the code, I'd be thankful!
With your example (if stored data is that short like "A" "B" "C" etc), id add
Code:
var %i = 1
while (%i < 7) {
  SET %slot.%i = <json parser stuff here>)
  set %slot.list = %slot.list %slot.%i
  inc %i    
}

so slot.list will be as " A B B B A C C"
and then use $findtok(%list,A,0,32) and $remtok(%list,A,0,32) till %numtok == 0.
Stored data will be 4 numbers for each variable that are ids to use with another api call which will retrieve the name of the related item id.
So next to the reality it'll be something like:
Code:
Slot 1 = 5402
Slot 2 = 5402
Slot 3 = 5390
Slot 4 = 5233
Slot 5 = 5233
Slot 6 = 5233

Will your suggestion still be viable to this situation?
Yes. $findtok(,,0,) will return total number of specified tokens, same for $remtok. For more details check section about tokens in help file.
Sorry for the typo, %i = 1 should be correct and shouldn't crash your mirc, in any case you can type control + break to break a loop in mIRC.
© mIRC Discussion Forums