Results 1 to 6 of 6

Thread: TReflectInvItem.count

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default TReflectInvItem.count

    Simba Code:
    function TReflectInvItem.count(item:variant):integer;
    var
      T:TReflectInvItemArray;
      i:integer;
    begin
      T.get(item);
      if (length(T) < 0) then
        exit(0);
      if (Reflect.Misc.VariantIsString(item)) then
      begin
        for i := 0 to high(T) do
          if (T[i].name = item) then
            result := result + 1;
      end
      else
      begin
        for i := 0 to high(T) do
          if (T[i].name = item) then
            result := result + 1;
      end;
    end;

    counts the number of a item in your inventory.

  2. #2
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

  3. #3
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    Isn't the for loop in the else block exactly the same?
    Looks like it. if if he would just call it as const, you dont need to worry about making sure it fits the variant type, and could do whatever.

    or instead of variant type, could just make overloads to reduce the logic required in it and let the interpreter take care of it.

  4. #4
    Join Date
    Nov 2014
    Posts
    104
    Mentioned
    12 Post(s)
    Quoted
    59 Post(s)

    Default

    I'm not sure how we overlooked this! We will be adding this feature soon.

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    Looks like it. if if he would just call it as const, you dont need to worry about making sure it fits the variant type, and could do whatever.

    or instead of variant type, could just make overloads to reduce the logic required in it and let the interpreter take care of it.
    I only did it because that's how it was done in the include

  6. #6
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    Quote Originally Posted by Robert View Post
    I only did it because that's how it was done in the include
    Ahh, but the include does it correctly

    If you pass a ID to your function it will error, I think that was their point. You compare the Name = Item both times. If it is an Id it will try to compare a string to an int, erroring out. You need to make it T[I].Id = Item on the second loop
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

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
  •