ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Cerveza on July 11, 2011, 07:02:26 PM

Title: For loop and findID's
Post by: Cerveza on July 11, 2011, 07:02:26 PM
Having trouble checking status of things in my pack. This is for a pretty slick sub I'm writing and I want it working good.

I want to check for a property on several items in my pack, and have it react if the property is one thing, and not react if it's something else.

I read through another post regarding this and followed it, not working. Here's what I have:

Code: [Select]
sub THIS_SUB_NOT_WORKING
  finditem %1 C_ , #backpackID
  if #findCnt < 1
    return
  set %count #findCnt
  for #findindex 1 %count
    set %item . #findindex #findID
  for %loop 1 %count
  {
    msg %item $ ; always returns N/A
    gosub Check_Item %item . %loop
  }
return

sub Check_Item
  event property %1
  if SOMETHING in #property
    return

%item always returns N/A, and I need something that will check through all the items.
Title: Re: For loop and findID's
Post by: UOMaddog on July 11, 2011, 07:18:08 PM
I could be wrong, but I think you're getting

. #findindex 

instead of

( %item . #findindex )

Of course, I could be misunderstanding completely...
Title: Re: For loop and findID's
Post by: Cerveza on July 12, 2011, 02:20:37 AM
I'm not sure at all, but I'm definitely not getting any of the ID's of the items found, which is what I need to get.

In case I'm not clear...

I have 10 widgets in my pack, I want to scan all 10 and get the property of each one individually so I can alter it, but I want to leave the already altered ones alone. The #property portion works fine, what I'm having trouble with is counting the items (works) then evaluating them individually (problem).

I always thought that #findCnt would cycle through the item ID's, I guess it doesn't.

Would doing a findItem/ignoreitem in the for loop be the way to go? For some reason this solution seems a bit harsh to me.

Code: [Select]
for %count 1 #findCnt
{
finditem %1 C_ , #backpackID
event property #findID
if something notin #property
  do stuff to it
ignoreitem #findID
}
Title: Re: For loop and findID's
Post by: 12TimesOver on July 12, 2011, 02:48:05 AM
Maddog was on the right track. You need to cycle through your #findindex. #findindex basically holds the values of all your results. I think you want something along the lines of

Code: [Select]
finditem * C_ , #backpackid
for #findindex 1 #findcnt
   {
   event property #Findid
   do whatever it is you want to do
   }
Title: Re: For loop and findID's
Post by: Cerveza on July 12, 2011, 02:51:28 AM
Lemme give that a whirl, I ran into an old problem the way I was doing it, #findItem will equal X when it runs out...
Title: Re: For loop and findID's
Post by: Cerveza on July 12, 2011, 02:56:59 AM
That didn't work either...

And, the old problem is that when #findCnt = 0 then #findID = X

There must be some way of doing this.
Title: Re: For loop and findID's
Post by: 12TimesOver on July 12, 2011, 03:27:16 AM
That didn't work either...

And, the old problem is that when #findCnt = 0 then #findID = X

There must be some way of doing this.

Maybe I did it wrong or I'm misunderstanding what you're trying to do but I'm pretty sure that is at least the right track.

This seems right to me but I'm not testing anything as a type it up:

You could circumvent the FindID = X problem by checking that the value of #Findcnt > 0 before performing your loop or something.

Code: [Select]
finditem * C_ , #backpackid
if #findcnt > 0
   {
   for #findindex 1 #findcnt
      {
      event property #Findid
      do whatever it is you want to do
      }
   }

X
Title: Re: For loop and findID's
Post by: Cerveza on July 12, 2011, 04:05:53 AM
Sorry 12x, that doesn't work. It's not #findCnt > 0 that is the problem. When you do a #findID you get a #findCnt but when you use that #findCnt in a for loop you will get the total amount in your pack, and when the for loop gets down to 1 item in your pack it will find the 0 item as well, which has an ID of "X".

I had a way of dealing with this, just gotta find it.

Something like

if #findID = X

I'll have to see where that is and try it.

I'm not doing a very good job of explaining this, I kinda want to keep the final product a secret until it's working. It'll be one of those "jeez, why hasn't this already been done" things, then people will post "Oh yeah, I've been using one I wrote for years", and I'll reply "then why didn't you release it so others could use it?" and they'll be all "sorry, didn't realize it was that useful" and I'll be like "well duh" and they'll be like "you don't have to be so mean" and I'll be like "BANHAMMER! WHOOMP".

Ok, lets just use this as an example. You have 6 bows in your backpack, some are toggled as a quest item and some are not toggled as a quest item.

Without using a goto, go through all 6 bows and determine if they are a quest item or not. If they are then skip over them and if they are NOT then toggle them as a script item.

Code: [Select]
finditem %bows C_ , #backpackID
if #findCnt > 0
  {
    for %whateverCauseThisDoesntDoAnythingReallyIThink 1 #findCnt
    {
      event property #findID
      if quest notin #property
      {
        toggle quest item to on
      }
    ignoreitem #findID
    }
  }

What I may have to do is something like this:

Code: [Select]
finditem %bows C_ , #backpackID
if #findCnt > 0
  {
    for %whateverCauseThisDoesntDoAnythingReallyIThink 1 #findCnt
    {
      if #findID <> X
        {
          event property #findID
          if quest notin #property
          {
            toggle quest item to on
          }
          ignoreitem #findID
        }
    }
  }
Title: Re: For loop and findID's
Post by: 12TimesOver on July 12, 2011, 04:27:14 AM
Your example is exactly what I've been planning, and half-heartedly working on, for my XIIx version of the old Craftmatic which is actually no longer recognizable as the old Craftmatic hehe.

I gotcha on the for loop piece now and I remember a thread a while back that was talking about this issue here on the site. Never having run into it myself I don't recall what the best solution ended up being.

I am off to go test a couple things of my own now because I'm feeling confident that cycling through the index is the way to go. I'll throw out a snippet once I figure out something. I'm working from home today lol.

X
Title: Re: For loop and findID's
Post by: JustAnotherFace on July 12, 2011, 04:46:32 AM
"Oh yeah, I've been using one I wrote for years", and I'll reply "then why didn't you release it so others could use it?" and they'll be all "sorry, didn't realize it was that useful" and I'll be like "well duh" and they'll be like "you don't have to be so mean" and I'll be like "BANHAMMER! WHOOMP".

You big Meanie-Head!!

JaF
Title: Re: For loop and findID's
Post by: UoLugnutz on July 12, 2011, 05:22:02 AM
Would there be a difference in the string length between A and B? Maybe can check that way.

Title: Re: For loop and findID's
Post by: 12TimesOver on July 12, 2011, 05:39:11 AM
So this works wonderfully. This test snippet confirms that the for loop should look as I mentioned to cycle through the list of items matched by the FindItem. The below will simply cycle through everything in your backpack and display some detail about them. In your example you would simply replace my "Display" stuff in the below to "If Quest in #Property" yadda yadda.

Code: [Select]
finditem * C_ , #backpackid
for #findindex 1 #findcnt
   {
   event property #findid
   Display OK Object Information:$
      + , #spc , #spc , #spc , FindCnt: #Findcnt $
      + , #spc , #spc , #spc , FindIndex: #Findindex $
      + , #spc , #spc , #spc , Item Type: #FindType $
      + , #spc , #spc , #spc , Item ID: #ltargetid $
      + , #spc , #spc , #spc , Color: #findcol $
      + , #spc , #spc , #spc , Properties: #property $
   }
Halt
Title: Re: For loop and findID's
Post by: Cerveza on July 12, 2011, 05:58:15 AM
You don't get a single entry that is a 0 or an X without any information?

I'd love to see this tested with several of the same type items in your pack and targetting only them.

Then do the event property and msg the findID's.

Code: [Select]
finditem TSF C_ , #backpackID ; daggers - have like 10 in your pack
for #findindex 1 #findcnt
  {
  event property #findID
  msg #findindex #findID $
  }
halt

Try that, maybe not with daggers but with several of the same item. Then post up the messages. I'm betting one of them will be an "X"
Title: Re: For loop and findID's
Post by: Cerveza on July 12, 2011, 01:12:54 PM
Working! The last one is working just fine, tks 12x!

Now on to the second problem, then posting up the finished product.