Author Topic: Script not sorting properly (python)  (Read 4538 times)

0 Members and 1 Guest are viewing this topic.

Offline JlMTopic starter

  • Jr. Member
  • **
  • Posts: 10
  • Activity:
    0%
  • Reputation Power: 1
  • JlM has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Script not sorting properly (python)
« on: September 12, 2018, 04:31:42 AM »
0
I have the following script to sort bods in my bag. It currently only puts blacksmith bods Into my book that is labeled tailor. Any help would be appreciated.

def SortBods():
    res = FindTypeEx(8793, 0, Backpack(), False)
    FoundBooks = GetFindedList()
    res = FindTypeEx(8792, 1155, Backpack(), False)  # Tailor
    FoundTailorBods = GetFindedList()
    res = FindTypeEx(8792, 1102, Backpack(), False)  # Blacksmith
    FoundBlacksmithBods = GetFindedList()
    for book in FoundBooks:
        tooltip = GetTooltip(book)
        if 'tailor' in tooltip:
            for tbod in FoundTailorBods:
                MoveItem(tbod, 0, book, 0, 0, 0)
                Wait(100)
        else:
            for bbod in FoundBlacksmithBods:
                MoveItem(bbod, 0, book, 0, 0, 0)
                Wait(100)

Offline Trigs

  • Jr. Member
  • **
  • Posts: 22
  • Activity:
    0%
  • Reputation Power: 1
  • Trigs has no influence.
  • Respect: +1
  • Referrals: 0
    • View Profile
Re: Script not sorting properly (python)
« Reply #1 on: September 12, 2018, 05:13:37 AM »
0
Assuming it's putting BODs in any book, the majority of the code seems to be working.

The only portion in question really is

Code: [Select]
        tooltip = GetTooltip(book)
        if 'tailor' in tooltip:

So I'd print the tooltip print(tooltip) or something to the logger so you can see if that string actually contains "tailor"... and possibly your book is named "Tailor" and that string find is case sensitive


Offline Trigs

  • Jr. Member
  • **
  • Posts: 22
  • Activity:
    0%
  • Reputation Power: 1
  • Trigs has no influence.
  • Respect: +1
  • Referrals: 0
    • View Profile
Re: Script not sorting properly (python)
« Reply #2 on: September 12, 2018, 08:54:43 AM »
0
Ok found out 'tailor' and book titled Tailor, don't match up. So it adds tailors now but fails to put Smith bods Into that book. How Do I make it loop back to the top to check again if there is still a bod. Or have it cycle it until no more bods are in bag?

Nice, I suspected that was the case :)

As for the new issue... Although I think it could be restructured a bit ( more below ) I don't really see what would prevent it from putting smith bods in.

A few things to check:
- Does FoundBlacksmithBods  actually contain info? Or check FindCount() after the FindTypeEx() call, maybe the color could be wrong?
- Does FoundBooks actually contain 2 ( or more ) books?

I'd suggest an approach like this ( warning psuedo code ) it might not ( probably wont ) work right off the bat since I'm coding into a browser lol

Code: [Select]
# Function to find a book by name in your pack
def findNamedBook(searchStr )
    res = FindTypeEx(8793, 0, Backpack(), False)
    FoundBooks = GetFindedList()
    for book in FoundBooks:
        tooltip = GetTooltip(book)
        if searchStr in tooltip:
           return book
   # some error since no matching book found
return 0

tailorBook = findNamedBook('Tailor') # find our tailor book
smithBook = findNamedBook('Smith') # find our smith book

res = FindTypeEx(8792, 1155, Backpack(), False)  # Get all tailor bods
FoundTailorBods = GetFindedList()
for tbod in FoundTailorBods:
   MoveItem(tbod, 0, tailorBook , 0, 0, 0)
   Wait(100)

res = FindTypeEx(8792, 1102, Backpack(), False)  # Get all smith bods
FoundSmithBods = GetFindedList()
for bod in FoundSmithBods :
   MoveItem(tbod, 0, tailorBook , 0, 0, 0)
   Wait(100)


I think it's a little more clear, and avoids nested / redundant loops
« Last Edit: September 12, 2018, 08:56:33 AM by Trigs »

Offline JlMTopic starter

  • Jr. Member
  • **
  • Posts: 10
  • Activity:
    0%
  • Reputation Power: 1
  • JlM has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Script not sorting properly (python)
« Reply #3 on: September 12, 2018, 08:56:23 AM »
0
Ok found out 'tailor' and book titled Tailor, don't match up. So it adds tailors now but fails to put Smith bods Into that book. How Do I make it loop back to the top to check again if there is still a bod. Or have it cycle it until no more bods are in bag?

Nice, I suspected that was the case :)

As for the new issue... Although I think it could be restructured a bit ( more below ) I don't really see what would prevent it from putting smith books in.

A few things to check:
- Does FoundBlacksmithBods  actually contain info? Or check FindCount() after the FindTypeEx() call, maybe the color could be wrong?
- Does FoundBooks actually contain 2 ( or more ) books?

I'd suggest an approach like this ( warning psuedo code )

Code: [Select]
def findNamedBook(searchStr )
    res = FindTypeEx(8793, 0, Backpack(), False)
    FoundBooks = GetFindedList()
    for book in FoundBooks:
        tooltip = GetTooltip(book)
        if searchStr in tooltip:
           return book
# some error since no matching book found
return 0

tailorBook = findNamedBook('Tailor')
smithBook = findNamedBook('Smith')

res = FindTypeEx(8792, 1155, Backpack(), False)  # Tailor
FoundTailorBods = GetFindedList()
for tbod in FoundTailorBods:
   MoveItem(tbod, 0, tailorBook , 0, 0, 0)
   Wait(100)

res = FindTypeEx(8792, 1102, Backpack(), False)  # Blacksmith
FoundSmithBods = GetFindedList()
for bod in FoundSmithBods :
   MoveItem(tbod, 0, tailorBook , 0, 0, 0)
   Wait(100)


I think it's a little more clear, and avoids nested / redundant loops

I figured it out. I just told it to sort 4 times in a row in the body of code

Offline Trigs

  • Jr. Member
  • **
  • Posts: 22
  • Activity:
    0%
  • Reputation Power: 1
  • Trigs has no influence.
  • Respect: +1
  • Referrals: 0
    • View Profile
Re: Script not sorting properly (python)
« Reply #4 on: September 12, 2018, 09:16:11 AM »
0
I figured it out. I just told it to sort 4 times in a row in the body of code

That's one way to go about it I guess   :-\\  definitely a cludge tho if you just copy and pasted the code a few times !

Tags: