Results 1 to 7 of 7

Thread: Error: Out of type range

  1. #1
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default Error: Out of type range

    I'm trying to add an array for a record but it keeps either complaining about the array or throws out of type range. Can someone provide some insight as to what I'm doing wrong?

    I went ahead and created a new record to hold my "array" but maybe I'm not doing this correctly? I'm assuming I may have to actually have it hold a specific set of ID's such as only 4 and then put in [x1, x2, x3, x4] to get past it. If however this is the only fix/workaround then would I be able to input default values such as 0 in the scenario where I only have 2 id's for a mob opposed to 4? ex. [x1, x2, 0, 0]

    Simba Code:
    program BlitzFighter;
    {$i oglib/lib/core/core.simba}

    {BlitzFighter v0.01}

    {SCRIPT SETTINGS}

    const
      SHOW_PAINT = false;

    {END OF SETTINGS}

    const
      scriptVersion = '0.01';

    type tMobID = record
      ID: glModelArray;
    end;

    type MOB = record
      Name,
        attackOption: String;
      mobID: tMobID;
      minWait,
        maxWait: integer;
      thresholds,
        selfRegen: boolean;
    end;

    var
      fightFail,
        scriptPaintBMP: integer;
      clientCenter: TPoint;
      playerID: uInt32;
      Goblin: mob;

    {PROCEDURE -- Debug
    Purpose: Custom console debugging procedure.
    Comments: By Clarity.}

    procedure Debug(message: string);
    begin
      writeln('BlitzFighter v' + scriptVersion + ' || ' + toStr(getTimeRunning) + ' || ' + message);
    end;

    {PROCEDURE -- doNothing()
    Purpose: Scan React.
    Comments: None.}

    procedure doNothing();
    begin
    end;

    {PROCEDURE -- rotateCamera()
    Purpose: rotates Camera.
    Comments: None.}

    procedure rotateCamera();
    begin
      minimap.setDegrees(minimap.getDegrees()+random(-45,45));
    end;

    {PROCEDURE -- shortWait()
    Purpose: Cuz I'm lazy and want to type less.
    Comments: None.}

    procedure shortWait();
    begin
      wait(randomRange(600,1800));
    end;

    {FUNCTION -- canFight(): boolean
    Purpose: Detects if we are already in combat and capable of fighting.
    Comments: None.}

    function canFight(): boolean;
    begin
       if not (combat.hasTarget()) then
        result:= true;
    end;

    {PROCEDURE -- mob.Init()
    Purpose: For mob records.
    Comments: None.}

    procedure MOB.Init(_Name: String; _mobID: tMobID; _attackOption: String; _minWait: integer; _maxWait: integer; _thresholds: boolean; _selfRegen: boolean);
    begin
      Self.Name := _Name;
      Self.mobID := _mobID;
      Self.attackOption := _attackOption;
      Self.minWait := _minWait;
      Self.maxWait := _maxWait;
      Self.thresholds := _thresholds;
      Self.selfRegen := _selfRegen;
    end;

    {PROCEDURE -- tMobID.Init()
    Purpose: For mob records.
    Comments: None.}

    procedure tMobID.Init(_mobArray: glModelArray);
    begin
      Self.ID := _mobArray;
    end;

    {PROCEDURE -- loadMobs()
    Purpose: Loads mob data.
    Comments: None.}

    procedure loadMobs();
    begin
      Goblin.Init('Goblin', ogl.getModels[1496395506, 163684431, 1574583763, 3748622621, 3626760128, 2071972491], 'ttack Gobl', 1000, 3000, true, true);
    end;

    {PROCEDURE -- safeEscape()
    Purpose: Fight logic.
    Comments: None.}

    procedure safeEscape();
    begin
    end;

    {PROCEDURE -- useThresholds()
    Purpose: Strategic use of thresholds.
    Comments: None.}

    procedure useThresholds();
    begin
    end;

    {PROCEDURE -- mob.Attack()
    Purpose: Fight logic.
    Comments: None.}

    procedure mob.Attack();
    var
      mobIDArray: glModelArray;
      mobTPA: TPointArray;
      nextFight: tCountDown;
    begin
      if fightFail > 5 then
        safeEscape();
      if canFight() and nextFight.isFinished() then
      begin
        if ogl.getModels(Self.mobID) then
        begin
          if (mobIDArray := ogl.getModels(Self.mobID)).indexes then
          begin
            mobTPA:= ogl.getClientMidPoint().closest(mobIDArray).toPointArray;
            if not mobTPA[0].adjustPosition(0, -30).isVisible() then
            begin
              rotateCamera();
              shortWait();
            end;
            Case random(4) of
            1: mouse.rightClickOption(mobTPA[0].adjustPosition(0, -30).randomizePointEllipse(30), [Self.attackOption],600);
            2: mouse.click(mobTPA[0].adjustPosition(0, -10).randomizePointEllipse(30));
            3: mouse.click(mobTPA[0].adjustPosition(0, -20).randomizePointEllipse(40));
            4: mouse.rightClickOption(mobTPA[0].adjustPosition(0, -20).randomizePointEllipse(40), [Self.attackOption],600);
            end;
          end;
          nextFight.setTime(normalRandom(Self.minWait, Self.maxWait));
          if actionBar.getAdrenaline() >=50 and combat.hasTarget() and Self.thresholds = true then
            useThresholds();
          if actionBar.getAdrenaline() >=1 and (not (combat.hasTarget())) and Self.selfRegen = true then
          begin
            if actionBar.getLifePoints() <80 then
            begin
              actionBar.setRegenerate(true);
              while actionBar.getAdrenaline >=1 do
                shortWait();
            end;
          end;
        end;
      end
      else
      begin
        inc(fightFail);
        exit;
      end;
    end;

    {PROCEDURE -- mainLoop()
    Purpose: Script main loop.
    Comments: None.}

    procedure mainLoop();
    var
      reaction: procedure() = @doNothing;
    begin
      if canFight() then
        Goblin.Attack()
      else
      reaction();
    end;

    {PROCEDURE -- autoUpdateMe
    Purpose: Autoupdates the script.
    Comments: By Shuttleu, modified by Ashaman88 and Clarity}

    procedure autoUpdateMe;
    var
      Neifile: Integer;
      OnlineVersion, NewScript, NeiFeilNennen: string;
    begin
      Debug('Checking for script updates...');
      OnlineVersion := GetPage('http://pastebin.com/raw/fSG5AKXw');
      Debug('Online Script Version: ' + OnlineVersion);
      Debug('Local Script Version: ' + ScriptVersion) if (trim(OnlineVersion) > ScriptVersion) then
      begin
        Debug('New script version online!');
        Debug('Autoupdating to newer version.');
        NewScript := GetPage('http://pastebin.com/raw/cryBF3SQ');
        NeiFeilNennen := ScriptPath + 'BlitzKrieger v' + OnlineVersion + '.simba';
        Neifile := Rewritefile(NeiFeilNennen, true);
        try
          WriteFileString(Neifile, NewScript);
        except
          begin
            Debug('Fatal error writing to ' + NeiFeilNennen + '!');
            Terminatescript;
          end;
        end;
        CloseFile(Neifile);
        Debug('New script downloaded to ' + NeiFeilNennen + '! Terminating old script, please use the new version.');
        writeln('New script downloaded to ' + NeiFeilNennen + '! Terminating old script, please use the new version.');
        TerminateScript;
      end
      else
        Debug('You have the latest version of the script!');
    end;

    {PROCEDURE -- checkForFiles
    Purpose: Checks to see if file downloading is required.
    Comments: By Kevin, modified by Clarity}

    procedure checkForFiles(filePath, message, link: string);
    var
      progFile: longInt;
      fileName: string;
    begin
      fileName := AppPath + filePath;
      try
        if not fileExists(fileName) then
        begin
          Debug('-- INSTALLATION STATUS: ' + message + ' does not exist - Downloading now.');
          progFile := createFile(fileName);
        end
        else
        begin
          Debug('-- INSTALLATION STATUS: ' + message + ' exists.');
          exit;
        end;
        closeFile(progFile);
        progFile := rewriteFile(fileName, false);
        writeFileString(progFile, getPage(link));
        Debug('-- INSTALLATION STATUS: ' + message + ' has been downloaded.');
      finally
        if (progFile > 0) then
          closeFile(progFile);
      end;
    end;

    {PROCEDURE -- installAssets
      Purpose:  Determines whether files exist and dictates their installation.
      Comments: By Clarity}

    procedure installAssets;
    begin
      Debug('Please wait...now installing BlitzKrieger image assets to your computer...');
      if not directoryExists(appPath + 'scripts/BlitzKrieger/Images/') then
      begin
        try
          createDirectory(appPath + 'scripts/BlitzKrieger/Images/');
          Debug('Created a new folder in Simba/Scripts/');
        except
        end;
      end;
      checkForFiles('scripts/BlitzKrieger/Images/BlitzFighter.png', 'BlitzFighter', 'imgur path');
    end;

    procedure initialize();
    begin
      autoUpdateMe;
      //installAssets();
      loadMobs();
      if SHOW_PAINT then
      begin
        scriptPaintBMP := loadBitmap(appPath + 'Scripts\BlitzKrieger\Images\BlitzFighter.png');
        fastReplaceColor(scriptPaintBMP, 0, 1);
      end;
      clientCenter:=ogl.getClientMidPoint();
    end;
    begin
      clearDebug();
      ogl.setup(1200, 800);
      ogl.setCacheTime(120);
      ogl.setColourTolerance(2);
      ogl.setDebugMode('m');
      initialize();

      repeat
        //writeln(ogl.getTextures(117810));
        mainLoop;
      until false;
    end;
    Last edited by BlitzKrieger; 01-09-2017 at 06:22 AM.

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Why not just do this?
    Simba Code:
    type MOB = record
      Name, attackOption: String;
      mobID: glModelArray;
      minWait, maxWait: integer;
      thresholds, selfRegen: boolean;
    end;
    I don't see the point of tMobID.
    Last edited by Citrus; 01-09-2017 at 07:25 AM.

  3. #3
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Why not just do this?
    Simba Code:
    type MOB = record
      Name, attackOption: String;
      mobID: glModelArray;
      minWait, maxWait: integer;
      thresholds, selfRegen: boolean;
    end;
    I don't see the point of tModID.
    I tried - it throws the same error. I tried a multitude of alterations resulting in
    Error: Expected variable of type "array of record [0]UInt32; [4]Int32; [8]Int32; [12]Int32; end", got "array [0..5] of Int32" at line 93, column 14 at line 93
    Error: Can't assign "array of record [0]UInt32; [4]Int32; [8]Int32; [12]Int32; end" to "record [0]UInt32; [4]Int32; [8]Int32; [12]Int32; end" at line 80
    Error: Can't assign "array of Int32" to "array of record [0]UInt32; [4]Int32; [8]Int32; [12]Int32; end" at line 80

    Bottom line is I'm absolutely confused and that seems to be the most logical approach at this point. I haven't tried what I "think" is going to fix it yet as it's late and I need to get to sleep but plan on attempting that tomorrow - See OP.

    Edit: Ultimately I think I have to get rid of the array portion and trick it into thinking it's not an array while retaining it's use as an array later in the script. (gah my head hurts).
    Last edited by BlitzKrieger; 01-09-2017 at 06:50 AM.

  4. #4
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    I'm pretty sure your understanding of getModels() is wrong. It gives you the models that are currently on your screen. You seem to already have the ID for your mob, so just use it in your combat procedure. e: see below

    see: https://villavu.com/forum/showthread.php?t=112486
    Last edited by Citrus; 01-09-2017 at 05:00 PM.

  5. #5
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    I don't normally help with ogLib as it is a big clusterfu*k, but here you go anyway. In your loadMobs procedure:

    Simba Code:
    Goblin.Init('Goblin', ogl.getModels[1496395506, 163684431, 1574583763, 3748622621, 3626760128, 2071972491], 'ttack Gobl', 1000, 3000, true, true);

    The second parameter, ogl.getModels, returns a glModelArray. However, in your .init() procedure, the second parameter is of tMobId type, not a glModelArray.

    Similar issue in your mob.attack() procedure. When you go ogl.getModels(Self.mobID) and are passing in the tMobId type you created. ogl.getModels cannot take a tMobId type.

    Alternatively, you could:

    Simba Code:
    type TMob = record
      name, attackOption: String;
      mobID: array of uInt32; // Pass in an int array instead
      minWait, maxWait: integer;
      thresholds, selfRegen: boolean;
    end;

    And change the .init method to take the new type:
    Simba Code:
    procedure MOB.Init(_Name: String; _mobID: array of uInt32; ...);
    begin
      Self.Name := _Name;
      Self.mobID := _mobID; // May have to setLength() first
      //... etc
    end;

    So when you use it, it will now look like:
    Simba Code:
    procedure loadMobs();
    begin
      Goblin.Init('Goblin', [1496395506, 163684431, 1574583763], ...);
      Cow.Init('Cow', [1496395506], ...);
      Pig.Init('Obscurity The Pig', [1496395506, 1496395506, 163684431, 1574583763, 1496395506, 163684431], ...);
    end;

    Then when you call ogl.getModels(Self.mobID) you are passing in an array of uInt32, which should work.

  6. #6
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    @Citrus; Thanks for all the help it happened to be what @Laquisha; stated. Also - I for some reason can't give you reputation..? @Laquisha; Thanks that makes sense.

    I went down the path of glmodelArray because I was originally doing Array of int32 not uint32 and it was throwing similar errors and got stuck on thinking I needed to trick it into being an array of some sort so in my head assumed "well it's a glmodelArray".

    Is there some sort of difference between int32 and uint32?

    Appreciate the guidance!

  7. #7
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by BlitzKrieger View Post
    Is there some sort of difference between int32 and uint32?
    The 'u' is for unsigned.
    see: http://wiki.freepascal.org/Variables_and_Data_Types. Look at word and longword vs. smallint and longint

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •