mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
het, i have been working on a game for a little while now, and all is going good, however, once the games gets to checking the numbers and counting the scores, i get a freeze, could be 1/2 a sec, to 3-4-5 seconds, depending on how many players joined in that round, so basically what i am looking for, is help in making the following code faster/better, to try to reduce the lenght of the freeze, or hopefully, stop the freeze all together.....in the following code, i have some custome i dentifer, and commands, so i will post those under the code, so you may better understand what its doing...:


Code:
 

alias comparenum {
  cplay -r won
  var %a = $ini(inplay.ini,generate,0), %b = $cplay(numbers,norm1), %c = $cplay(numbers,norm2), %d = $cplay(numbers,jackpot), %e = $cplay(numbers,bonus)
  while (%a > 0) {
    comparenum2 %a %b %c %d %e
    dec %a
  }
  echo 3 -ae *** Numbers Generated, Points Calculated, And Scores Completed, Notifying User Of New Scores...
  balance
}
alias -l comparenum2 {
  var %a = $1, %b = $2, %c = $3, %d = $4, %e = $5
  var %f = $cplay(betnum,$ini(inplay.ini,generate,%a)), %g = $cplay(wadge,$ini(inplay.ini,generate,%a))
  if ($istok(%f,%b,45)) {
    cplay won $ini(inplay.ini,generate,%a) $iif($cplay(won,$ini(inplay.ini,generate,%a)),$calc($ifmatch + (%g + (%g * $cset(main,normal)))),$calc(%g + (%g * $cset(main,normal))))
    cplay norm1 win $cplay(norm1,win) $ini(inplay.ini,generate,%a)    
  }
  else {
    cplay norm1 loss $cplay(norm1,loss) $ini(inplay.ini,generate,%a)
  }
  if ($istok(%f,%c,45)) {
    cplay won $ini(inplay.ini,generate,%a) $iif($cplay(won,$ini(inplay.ini,generate,%a)),$calc($ifmatch + (%g + (%g * $cset(main,normal)))),$calc(%g + (%g * $cset(main,normal))))
    cplay norm2 win $cplay(norm2,win) $ini(inplay.ini,generate,%a)
  }
  else {
    cplay norm2 loss $cplay(norm2,loss) $ini(inplay.ini,generate,%a)
  }
  if ($istok(%f,%d,45)) {
    cplay won $ini(inplay.ini,generate,%a) $iif($cplay(won,$ini(inplay.ini,generate,%a)),$calc($ifmatch + (%g + (%g * $cset(main,jackpot)))),$calc(%g + (%g * $cset(main,jackpot))))
    cplay jackpot win $cplay(jackpot,win) $ini(inplay.ini,generate,%a)
  }
  else {
    cplay jackpot loss $cplay(jackpot,loss) $ini(inplay.ini,generate,%a)
  }
  if ($istok(%f,%e,45)) {
    cplay won $ini(inplay.ini,generate,%a) $iif($cplay(won,$ini(inplay.ini,generate,%a)),$calc($ifmatch + (%g + (%g * $cset(main,bonus)))),$calc(%g + (%g * $cset(main,bonus))))
    cplay bonus win $cplay(bonus,win) $ini(inplay.ini,generate,%a)   
  }
  else {
    cplay bonus loss $cplay(bonus,loss) $ini(inplay.ini,generate,%a)
  }
  cplay lose $ini(inplay.ini,generate,%a) $calc($numtok($remove(%f,$cplay(numbers,norm1),$cplay(numbers,norm2),$cplay(numbers,jackpot),$cplay(numbers,bonus)),45) * %g)
}

 



thats the code right there, the other alias "balance" just sends a message to every user with their new balance.... here is the alias for "cplay"

Code:
 alias cplay {
  if ($isid) {
    var %a = $readini(inplay.ini,n,$1,$2)
    return %a
  }
  else {
    if ($1 == -r) {
      if (!$3) {
        remini inplay.ini $2
      }
      else {
        remini inplay.ini $2 $3
      }
    }
    else {
      writeini -n inplay.ini $1-
    }
  }
} 


so you see, if i have 30, 40+ players that round, it will take a long time to process all the info, and thus mirc freezes up untill its done.....
Thanks alot for any help in advance

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
One thing you could try is to "pseudo-thread" it by using a timer to call the alias again to process the next batch of however many doesn't freeze you up too long...might be 5 or 10 or whatever. Have the timer call the alias with parameters and use those parameters to continue processing after a short break .. like .timer -m 1 250 or whatever value works. You'll have to play around with it to get it set right for your processor speed.

In your while loop condition, you have while (%a > 0). Since 0 equates to $false, you can just use while (%a). When it reaches 0, it will drop out of the loop.

Where you're setting your %a %b %c %d %e variables, you can check first for $1 $2 $3 $4 $5 and use those values to make your alias "re-entrant" and process like 5 at a time instead of all of them. You might then switch your while condition to something like while ($calc(%a % 5)).

You could even set your timer to -m 1 100 and let it process just one at a time and start the timer. Granted, you're going to increase the time it takes to process the list, but you'll solve the problem of mIRC locking up for the time it takes it to complete all the work.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
ok, yeah i know afew little things i ca change like the "while (%a > 0)" but i didnt think it would make that much of a differance, umm, there is one thing you said i dont quite understand the meaning/what you mean:

:Where you're setting your %a %b %c %d %e variables, you can check first for $1 $2 $3 $4 $5 and use those values to make your alias "re-entrant" and process like 5 at a time instead of all of them. You might then switch your while condition to something like while ($calc(%a % 5))."


another little problem i have, is that, the "balance" part you see, if i do the while with a time, then it gets to the call to "balance" before it completed all the other ones, so the messages it sends are wrong, cause the other alias/timer isnt done processing the info yet, know what i mean?

perhaps you can show an example with what i posted about that little part of "sending them 5 at a time" or whatever ya wanna call it smile

thanks alot

Joined: Dec 2002
Posts: 774
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 774
I'd suggest you to use Hash tables instead of ini's as file processing is SLOW


Code:
//if ( khaled isgod ) echo yes | else echo no
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
nah, at first i was gonna, but all this info is o be stored in files, and may be transfered, and different file selected, settings changed, files shared, opened and edited, doesnt quite work the same with hash tables, yes hash tables are about 10 times+ faster, and more efficient, and yes, i concidered it, i concidered every option i had b4 starting this project, and ini files were the coise i made bassed on everything in total smile

Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
btw, all this code works just great, can have 10 players playing, and it doesnt freeze at all, or lag much, if any at all, the problem occurs when we get into playing it with 15, 20, 30+ ppl, thats when it gets the "freeze" period, it has been played"tested" with 46 players who actualed joined and bet, and had their scored and everything processed, and the "freeze" once it got to that code above, was about 3-4 seconds give or take a fraction or two, which really isnt bad if you concider how much data it is processing and cross referancing for each user....i am just hoping, or trying to find a way, to use the same thing as i am not, ini files, and basically that same code, but stop the freeze from occuring, perhaps a timer, or maybe sending less info at a time, or more info at a time, i'm not sure which will make it faters, or better, or whatever, but like i said, with the timer, the message to the user in the "balace" alias is wrong, because the messages(most of them) are sent b4 the times are done seding the info to that second alias to be processed,

(just a note, at first, i only had the one alias for "comparenum" the two you see there, were actually one, but i was getting the freeze, so i tried it on a time, and thats how i ended up with the two alises, but the timer like i send messed up the messages sent, but i was too lazy to combine the two aliases back into one single alias after i took the timer off, lol, probably because subconsiously i know i am probably gonna have to do it with a time if i really want to stop the freeze, lol)

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
OK, since you obviously can script, here's the basic idea:
Code:

alias comparenum {
  ;  Either accept parameters to continue processing
  if ($5) {
    var %a = $1, %b = $2, %c = $3, %d = $4, %e = $5
  }
  ;  or start the processing from scratch
  else {
    cplay -r won
    var %a = = $ini(inplay.ini,generate,0)
    var %b = $cplay(numbers,norm1)
    var %c = $cplay(numbers,norm2)
    var %d = $cplay(numbers,jackpot)
    var %e = $cplay(numbers,bonus)
  }
  
  comparenum2 %a %b %c %d %e
  dec %a
  
  ;  If, after this processing run, there are still more, call a millisecond timer to continue
  if (%a > 0) {
    .timer -m 1 200 comparenum %a %b %c %d %e
  }
  ;  or complete the script.
  else {
    echo 3 -aeti2 *** Numbers generated, points calculated, and scores completed, notifying user of new scores
    balance
  }
}


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
hmmm, ok thanks, i'll see what i can come up with smile


Link Copied to Clipboard