Author Topic: For loop and findID's  (Read 4317 times)

0 Members and 1 Guest are viewing this topic.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
For loop and findID's
« on: July 11, 2011, 07:02:26 PM »
0
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.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline UOMaddog

  • Maddog
  • Elite
  • *
  • *
  • Posts: 1625
  • Activity:
    0%
  • Reputation Power: 22
  • UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...
  • Gender: Male
  • Biggest B@D@$$ of the Universe
  • Respect: +165
  • Referrals: 8
    • View Profile
    • Insane UO
Re: For loop and findID's
« Reply #1 on: July 11, 2011, 07:18:08 PM »
0
I could be wrong, but I think you're getting

. #findindex 

instead of

( %item . #findindex )

Of course, I could be misunderstanding completely...
There are 10 kinds of people in this world: those that understand binary and those that don't!

Windows:  A 64-bit tweak of a 32-bit extension to a 16-bit user interface for an 8-bit operating system based on a 4-bit architecture from a 2-bit company that can't stand 1 bit of competition!

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: For loop and findID's
« Reply #2 on: July 12, 2011, 02:20:37 AM »
0
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
}
« Last Edit: July 12, 2011, 02:33:09 AM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: For loop and findID's
« Reply #3 on: July 12, 2011, 02:48:05 AM »
0
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
   }
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: For loop and findID's
« Reply #4 on: July 12, 2011, 02:51:28 AM »
0
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...
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: For loop and findID's
« Reply #5 on: July 12, 2011, 02:56:59 AM »
0
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.
« Last Edit: July 12, 2011, 03:03:45 AM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: For loop and findID's
« Reply #6 on: July 12, 2011, 03:27:16 AM »
0
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
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: For loop and findID's
« Reply #7 on: July 12, 2011, 04:05:53 AM »
0
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
        }
    }
  }
« Last Edit: July 12, 2011, 04:09:59 AM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: For loop and findID's
« Reply #8 on: July 12, 2011, 04:27:14 AM »
0
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
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline JustAnotherFace

  • Hero Member
  • *
  • Posts: 530
  • Activity:
    0%
  • Reputation Power: 8
  • JustAnotherFace has no influence.
  • Gender: Male
  • My new toy....
  • Respect: +24
  • Referrals: 4
    • View Profile
Re: For loop and findID's
« Reply #9 on: July 12, 2011, 04:46:32 AM »
0
"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
All that tyranny needs to gain a foothold is for people of good conscience to remain silent.
Thomas Jefferson

Offline UoLugnutz

  • Full Member
  • ***
  • Posts: 123
  • Activity:
    0%
  • Reputation Power: 2
  • UoLugnutz has no influence.
  • Respect: +25
  • Referrals: 0
    • View Profile
Re: For loop and findID's
« Reply #10 on: July 12, 2011, 05:22:02 AM »
0
Would there be a difference in the string length between A and B? Maybe can check that way.


Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: For loop and findID's
« Reply #11 on: July 12, 2011, 05:39:11 AM »
0
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
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: For loop and findID's
« Reply #12 on: July 12, 2011, 05:58:15 AM »
0
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"
« Last Edit: July 12, 2011, 06:35:52 AM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: For loop and findID's
« Reply #13 on: July 12, 2011, 01:12:54 PM »
0
Working! The last one is working just fine, tks 12x!

Now on to the second problem, then posting up the finished product.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Tags: