Author Topic: Scripting Stability  (Read 1149 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Scripting Stability
« on: February 21, 2011, 11:37:47 am »
I have a relatively large script that I wish to go through and try to make more stable. I was wondering what various things I should look out for which may cause any sort of instability.

A few things I've been told or know of:
  • dynamic arrays (I use a butt-load of these come to think of it)
  • CrossFunc (sometimes unavoidable, since there is a bunch of circular dependencies)
  • Calling the same function too fast (using OnAdminMessage, possible could make a buffer and distribute it AppOnIdle, although 1 sec delay is pretty large :()
  • Threads (not using, except for any event which is automatically in a thread, which afaik only OnPlayerSpeak uses, which I don't really use)
  • Multiple scripts (not exactly sure)
  • Large usage of (Get|Set)*Stat - replace with arrays
  • Writing to files very quickly - create a buffer, and write after it fills or at regular intervals
  • Writing to server console quickly
  • Having non-const parameters - huh?

I plan on doing some testing on these to see how much they affect stability.

Please share any alternatives to using some unstable methods.

If there is interest in this topic with what to look for when trying to stabilize your script, I'll organize everything in the first post to be nice looking with alternatives.
« Last Edit: February 26, 2011, 11:41:17 am by DorkeyDear »

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Scripting Stability
« Reply #1 on: February 21, 2011, 01:00:55 pm »
Using Get/SetSomethingStats too much.
for i := 1 to 32 do if GetPlayerStat(i, 'active') then if GetPlayerStat(i, 'alive') then...
If you have many loops like this, calling getplayerstat hundreds of times per second, try replacing them with arrays of booleans assigned for each player in OnActivateServer, OnJoinGame, OnLeaveGame, OnPlayerRespawn, OnPlayerKill etc.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Scripting Stability
« Reply #2 on: February 22, 2011, 04:45:44 am »
I'm using loads of dynamic arrays, and never had problems with them. Mainly do what tk said, which is replace all/most GetPlayerStat with your stored data. Rest is... good host. On some hosts scripts works just like a charm, on others they crashes every second. Mainly it's well known that windows hosts are more stable, but i wouldn't say it's a rule. I guess it's more hardware related.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Scripting Stability
« Reply #3 on: February 22, 2011, 09:23:43 pm »
I've personally never had stability problems with dynamic arrays (it was mentioned once to me though). The only issue I had with them is that some reason they don't always initialize to a 0-length array, and I need to do my_array := []; before doing anything with it.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Scripting Stability
« Reply #4 on: February 25, 2011, 04:33:13 pm »
try adding "const" to parameters whenever possible. I believe there was some stuff related to it

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Scripting Stability
« Reply #5 on: February 25, 2011, 09:56:54 pm »
Doing WriteLnFile very quickly (and probably WriteFile as well) does cause a script to become unstable. This specifically was the issue I was having.

I decided to make a buffer which, after it fills up or at regular intervals, is emptied and dumped into its associated file.

EDIT: also WriteLn`ing also causes some instability.
« Last Edit: February 26, 2011, 11:40:34 am by DorkeyDear »