Results 1 to 13 of 13

Thread: A quick question about integers

  1. #1
    Join Date
    Mar 2008
    Location
    In a cave
    Posts
    345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default A quick question about integers

    Well, I have a problem. I don't know if it's a bug or have I got something wrong.
    Anyways in my script I have this:
    SCAR Code:
    Bars := BarCount; //BarCount is a function that counts bars in my Inv and outputs the value as Integer
    Writeln('Made ' + IntToStr(Bars) + ' bars');

    Somehow it doesn't set Bars to BarCount. It adds BarCount to Bars initial value :S
    Is it supposed to do like that?
    A Chinese wiseman once said: "Shu ciu!", it was considered very smart, but now people know it means: "Something stinks here!"
    FalBuggySmelter v.1.31
    [Updated on the 1st of March 2010]
    RimmBugger BETA V1.8

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Post BarCount so we can help you.


  3. #3
    Join Date
    Feb 2007
    Location
    South East England
    Posts
    2,906
    Mentioned
    2 Post(s)
    Quoted
    8 Post(s)

    Default

    It should be

    SCAR Code:
    Bars := Bars + BarCount;

    Shouldn't it?
    Jus' Lurkin'

  4. #4
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You say BarCount counts all the bars and outputs the number. But is BarCount an integer function? If it is a procedure or a noninteger function, then that would cause the error.

    Try doing something like:

    SCAR Code:
    function BarCount: Integer;
    begin
      //do bar counting here
      Result := NumberOfBars; //this will return the number of bars, which will be the integer that shows up in the assignment you were trying to make.
    end;

    Edit: @ToF: it is called BarCount, so it sounds like it counts all of the bars. It's not just counting the new amount of bars to be added to the current amount.
    Last edited by JAD; 06-01-2009 at 02:08 AM.

  5. #5
    Join Date
    Feb 2007
    Location
    South East England
    Posts
    2,906
    Mentioned
    2 Post(s)
    Quoted
    8 Post(s)

    Default

    Maybe... but the he could be using BarCount as the global variable for how many bars he has.. ie BarCount := ItemExists[(DTM...] or w/e the function is.
    Jus' Lurkin'

  6. #6
    Join Date
    Mar 2008
    Location
    In a cave
    Posts
    345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well, this is my BarCount:
    SCAR Code:
    Function BarCount: integer;
    var
      i: integer;
      IBox: TBox;
    begin
      GameTab(4);
      for i := 1 to 28 do
        if ExistsItem(i) then
        begin
          IBox := InvBox(i);
          if FindDtm(BarDTM, x, y, IBox.x1, IBox.y1, IBox.x2, IBox.y2) then Inc(Result);
        end;
    end;

    It's supposed to count the bars currently in Inventory.

    And this is where I call it:
    SCAR Code:
    repeat
      if FindRandoms then
        if not LoggedIn then Exit;
      Bars := BarCount;
      Smelt(Players[CurrentPlayer].Strings[0], Amount);
      Wait(1000+Random(500));
      repeat
        if FindRandoms then
          if not LoggedIn then Exit;
        if (BarCount = Bars) then Break;
        Bars := BarCount;
        Writeln('Bars in Inventory: ' + IntToStr(BarCount));
        AntiBan;
        Wait(1000+Random(500));
      until (Bars = StrToInt(Amount));
    until not FindDTM(MOreDTM, x, y, MIX1, MIY1, MIX2, MIY2);

    And somehow it adds the integer that BarCount outputs to the var Bars instead of replacing Bars previous value. But I need to replace the previous value not the new value added to the old one
    A Chinese wiseman once said: "Shu ciu!", it was considered very smart, but now people know it means: "Something stinks here!"
    FalBuggySmelter v.1.31
    [Updated on the 1st of March 2010]
    RimmBugger BETA V1.8

  7. #7
    Join Date
    May 2008
    Location
    Canada
    Posts
    665
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    And somehow it adds the integer that BarCount outputs to the var Bars instead of replacing Bars previous value. But I need to replace the previous value not the new value added to the old one
    easy. At the end of the whole loop, or at the very beginning, Just make that value equal to zero.

  8. #8
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    I've seen this before. You need to initialize the Result value of BarCount at the begining of your function:

    SCAR Code:
    Function BarCount: integer;
    var
      i: integer;
      IBox: TBox;
    begin
      Result := 0; //Initialize Result to 0.
      GameTab(4);
      for i := 1 to 28 do
        if ExistsItem(i) then
        begin
          IBox := InvBox(i);
          if FindDtm(BarDTM, x, y, IBox.x1, IBox.y1, IBox.x2, IBox.y2) then Inc(Result);
        end;
    end;

  9. #9
    Join Date
    Mar 2008
    Location
    In a cave
    Posts
    345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    No guys, the problem isn't BarCount giving me wrong results, it's the Bars that gets the BarCount added to it all the time. When I used BarCount in the WriteLn, it wrote the correct number all the time, but when using Bars there, it wrote the sum of all previous and the current BarCount.
    For example:
    using
    SCAR Code:
    Writeln(BarCount);
    it printed like this:
    SCAR Code:
    1
    2
    3
    etc

    But when I used this:
    SCAR Code:
    Bars := BarCount;
    WriteLn(Bars);
    it printed:
    SCAR Code:
    1
    3
    6
    etc
    A Chinese wiseman once said: "Shu ciu!", it was considered very smart, but now people know it means: "Something stinks here!"
    FalBuggySmelter v.1.31
    [Updated on the 1st of March 2010]
    RimmBugger BETA V1.8

  10. #10
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by bugger0001 View Post
    No guys, the problem isn't BarCount giving me wrong results, it's the Bars that gets the BarCount added to it all the time. When I used BarCount in the WriteLn, it wrote the correct number all the time, but when using Bars there, it wrote the sum of all previous and the current BarCount.
    For example:
    using
    SCAR Code:
    Writeln(BarCount);
    it printed like this:
    SCAR Code:
    1
    2
    3
    etc

    But when I used this:
    SCAR Code:
    Bars := BarCount;
    WriteLn(Bars);
    it printed:
    SCAR Code:
    1
    3
    6
    etc
    Thats why I said initialize the Result variable.

  11. #11
    Join Date
    Mar 2008
    Location
    In a cave
    Posts
    345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I still don't get it...Why do I have to initialize the result of BarCount if it is outputting the correct integer? I'm not saying your right/wrong, but I guess I'm dumb enough to not understand it. Anyways going to try it
    A Chinese wiseman once said: "Shu ciu!", it was considered very smart, but now people know it means: "Something stinks here!"
    FalBuggySmelter v.1.31
    [Updated on the 1st of March 2010]
    RimmBugger BETA V1.8

  12. #12
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by bugger0001 View Post
    I still don't get it...Why do I have to initialize the result of BarCount if it is outputting the correct integer? I'm not saying your right/wrong, but I guess I'm dumb enough to not understand it. Anyways going to try it
    IDK its just something that SCAR does. Result is supposed to be created, initialized and destroyed when the procedure is called and ended but sometimes it doesn't and confuzzling stuff like this happens.

  13. #13
    Join Date
    Mar 2008
    Location
    In a cave
    Posts
    345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well, tried it and you were 100% correct about this
    Although I still don't get it, why SCAR does this :s
    For example I now tried this:
    SCAR Code:
    Repeat
      Bars := BarCount;
      Writeln('Bars made:' + IntToStr(Bars));
      Writeln('But actually: ' + IntToStr(BarCount));
      Wait(1500+Random(500));
    Until something;
    And it printed this:
    SCAR Code:
    Bars made:1
    But actually: 1
    Bars made:3
    But actually: 2
    Bars made:6
    But actually: 3
    Bars made:9
    But actually: 3
    Bars made:13
    But actually: 4

    PS I used the initial BarCount without Result := 0;
    A Chinese wiseman once said: "Shu ciu!", it was considered very smart, but now people know it means: "Something stinks here!"
    FalBuggySmelter v.1.31
    [Updated on the 1st of March 2010]
    RimmBugger BETA V1.8

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
  •