Author Topic: Fixing old scripts guide.  (Read 5254 times)

0 Members and 1 Guest are viewing this topic.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Fixing old scripts guide.
« on: July 25, 2013, 07:14:57 am »
Since there are so many problems with running old scripts on new server, i'm posting here a short guide on how to fix/adjust old scripts to work.

  • Missing semicolon: to solve it just add that missing semicolon, either in line it's pointing out or line above (see which one misses it)
  • Invalid variant type cast: Variants variables/function results are used without conversion in your code. Wrap them with IntToStr()/FloatToStr()/StrToInt() and similar to get rid of them
    Examples:
    Before:
    Quote
    var
      Msg: String;
    begin
      Msg := 'Player''s kills: ' + GetPlayerStat(1, 'Kills') + ', deaths: ' + GetPlayerStat(1, 'Deaths')
    end;
    After:
    Quote
    var
      Msg: String;
    begin
      Msg := 'Player''s kills: ' + IntToStr(GetPlayerStat(1, 'Kills')) + ', deaths: ' + IntToStr(GetPlayerStat(1, 'Deaths'))
    end;
  • Wrong division result: Some divisions that you expect to produce floating point value might give you rounded result (integer). To get rid of this, cast dividend, divisor or both to single or double (wrap them with Single() or Double())
    Examples:
    Before:
    Quote
    var
      Ratio: Single;
      Kills, Deaths: Integer;
    begin
      Kills := GetPlayerStat(1, 'Kills');
      Deaths := GetPlayerStat(1, 'Deaths');
      Ratio := Kills/Deaths;
    end;
    After:
    Quote
    var
      Ratio: Single;
      Kills, Deaths: Integer;
    begin
      Kills := GetPlayerStat(1, 'Kills');
      Deaths := GetPlayerStat(1, 'Deaths');
      Ratio := Single(Kills)/Single(Deaths);
    end;
  • Wrong Inc, Dec parameters: Replace them with variable assigments, like this:
    Examples:
    Before:
    Quote
    Inc(i, 1);
    Dec(Player[ID].Points, 5);
    After:
    Quote
    i := i + 1;
    Player[ID].Points := Player[ID].Points - 5;

If you encounter any other problems which you cannot solve yourself then please either reply here, or ask on #soldat.devs - i'll add solutions to those that seem to be common as well. Or if the errors seems to be API related, report it on bugtracker

Sorry for the inconvenience.
« Last Edit: February 09, 2016, 02:38:58 pm by FalconPL »
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.