mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2015
Posts: 3
N
Self-satisified door
OP Offline
Self-satisified door
N
Joined: Jun 2015
Posts: 3
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

Last edited by NoightSnoipe; 15/06/15 07:21 PM.
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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
}

Last edited by Wims; 15/06/15 09:12 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jun 2015
Posts: 3
N
Self-satisified door
OP Offline
Self-satisified door
N
Joined: Jun 2015
Posts: 3
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!

Joined: May 2015
Posts: 249
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
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.


Dont give a fish - teach to fish!
Joined: Jun 2015
Posts: 3
N
Self-satisified door
OP Offline
Self-satisified door
N
Joined: Jun 2015
Posts: 3
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?

Joined: May 2015
Posts: 249
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
Yes. $findtok(,,0,) will return total number of specified tokens, same for $remtok. For more details check section about tokens in help file.

Last edited by splinny; 15/06/15 09:03 PM.

Dont give a fish - teach to fish!
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard