Author Topic: Search, Ignore, Reset, Search again  (Read 3543 times)

0 Members and 1 Guest are viewing this topic.

Offline GuadahTopic starter

  • Full Member
  • ***
  • Posts: 119
  • Activity:
    0%
  • Reputation Power: 3
  • Guadah has no influence.
  • Gender: Male
  • Who farted?!
  • Respect: +29
  • Referrals: 3
    • View Profile
    • L%N Website
Search, Ignore, Reset, Search again
« on: July 13, 2008, 05:06:59 AM »
0
Well, I really wasn't sure what to title this post, but I'm working on a Ore Smelting script.  I'm able to get it working overall, but I am fine tuning some parts, and have hit a wall.

In my sub, where I identify the ore to be smelted, I am using a #findindex to search the bag, and I ignore all the ore that is not what I need (i.e. searching for iron).  Then do a search in the bag for #findcnt and if no ore is left in the bag, uncheck the checkbox, reset the ignoreitem and begin the next search.

Why do I ignore it? 
Well I'm using a Check Box in my menu that lets people select what type of ore they want to smelt at that time.  I know it seems silly, but even I have only wanted to smelt some Verite when I need some, and have a bag full of ore.

Now I have just figured out that #findindex is a great way to search through the bag, and I'm attempting to condense my scripts and simplify them without using #finditem over and over and over as I have done in the past.

Here is what I have written to accomplish my task.  However it always skips over the #findcnt section, so it never resets the ignoreitem, and does not uncheck the checkbox pertaining to that type of ore.

menu get iron pertains to the checkbox that is for Iron Ore.
%ore_type is the 4 types of ore that can be found (small broken, small, medium and large)
%resource_bag is obviously the bag full of ore
smelt_iron is the number of ore they are smelting at one time
%iron_color is 0, I have designated the color of each ore to identify them by, it works.

Code: [Select]
finditem %ore_type C_ , %resource_bag
menu get iron
if #menures = #true
   {
   for #findindex 1 #findcnt
       {
       if #findcol = %iron_color
          {
          set %ore #findid
          set %smelt smelt_iron
          }
       if #findcol <> %iron_col
          ignoreitem #findid 1
       if #findcnt < 1
          {
          menu set iron #false
          ignoreitem reset 1
          gosub select_ore
          }
       }
   return
   }

It repeats the #findindex  the number of times that I have ore in the pack, but once it goes through the last loop, it does not go through the if #findcnt < 1 section.

I know it may seem silly to you TM, but It looks correct to me.  Why isn't it working?

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Search, Ignore, Reset, Search again
« Reply #1 on: July 13, 2008, 06:01:55 AM »
0
Well it won't go through the #FINDCNT < 1 section because it's nested in your "for #findindex 1 #findcnt" loop.  If you do find something with "finditem" then this loop will always be greater than 0 and won't ever have a value that's 0.  Well, that's not necessary true because the way you wrote this and since you don't check for a successful "finditem" you can potentially count from 1 to 0 and I don't think you intended that.  You should always check for a successful "finditem" kinda like this:

Code: [Select]
finditem %ore_type C_ , %resource_bag
menu get iron
if #menures = #true && #findcnt > 0
{
  for #findindex 1 #findcnt
  {
    if #findcol = %iron_color
    {
      set %ore #findid
      set %smelt smelt_iron
    }
    else
    {
      ignoreitem #findid 1
    }
  }
}
else
{
  menu set iron #false
  ignoreitem reset 1
  gosub select_ore
}

It's still not clear why you really need to ignoreitem anything since any other search will go through everything again since you are looking for a specific color of an item and not a particular item type.
« Last Edit: July 13, 2008, 06:03:53 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline GuadahTopic starter

  • Full Member
  • ***
  • Posts: 119
  • Activity:
    0%
  • Reputation Power: 3
  • Guadah has no influence.
  • Gender: Male
  • Who farted?!
  • Respect: +29
  • Referrals: 3
    • View Profile
    • L%N Website
Re: Search, Ignore, Reset, Search again
« Reply #2 on: July 13, 2008, 06:11:23 AM »
0
Ah ty for the info.

I ended up going with this after your suggestion (didn't quite work with that last else command)
Code: [Select]
menu get iron
if #menures = #true
   {
   for #findindex 1 #findcnt
       {
       if #findcol = %iron_color
          {
          set %ore #findid
          set %smelt smelt_iron
          return
          }
       else
          {
          if #findcol <> %iron_col
          ignoreitem #findid 1
          }
       }
   menu set iron #false
   ignoreitem reset 1
   gosub select_ore
   }

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Search, Ignore, Reset, Search again
« Reply #3 on: July 13, 2008, 06:22:16 AM »
0
You really don't need that "if #findcol <> %iron_col" because the else is already doing that work for you.  I think this little snippet should be fine for you and will also be sure and check if there was a successful "finditem"

Code: [Select]
menu get iron
if #menures = #true
{
  finditem %ore_type C_ , %resource_bag
  if #findcnt > 0
  {
  for #findindex 1 #findcnt
  {
    if #findcol = %iron_color
    {
      set %ore #findid
      set %smelt smelt_iron
    }
    else
    {
      ignoreitem #findid 1
    }
  } 
  }
  else
  {     
    menu set iron #false
    ignoreitem reset 1
    gosub select_ore
  }
}
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline GuadahTopic starter

  • Full Member
  • ***
  • Posts: 119
  • Activity:
    0%
  • Reputation Power: 3
  • Guadah has no influence.
  • Gender: Male
  • Who farted?!
  • Respect: +29
  • Referrals: 3
    • View Profile
    • L%N Website
Re: Search, Ignore, Reset, Search again
« Reply #4 on: July 14, 2008, 12:18:57 AM »
0
I know, but I'm so OCD that I like to be able to read my code like a book.  It may not be the best habit, and maybe I'll be able to break myself out of it later.

I did however get the script fully functional and working.  Its posted over at WinUO.org if you want to take a look and give it a spin.  I'm very happy with how it came out, and how well it performs.

Thanks again for your help, support and advice.

Tags: