ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Khameleon on March 04, 2009, 06:39:47 PM

Title: Strings Drive my Crazy
Post by: Khameleon on March 04, 2009, 06:39:47 PM
I think I might have an Idea how to tackle this, but I'm hoping you guys have a better way to do this.


I'm trying to pick apart a string, mainly the price on an Item on a vendor.
what I'm thinking is to split the string up from $, then search for the word Price: and take everything from the right side of that?
is there a simpler form? I can't seem to figure it out :)
Title: Re: Strings Drive my Crazy
Post by: TrailMyx on March 04, 2009, 07:15:26 PM
I think I might have an Idea how to tackle this, but I'm hoping you guys have a better way to do this.


I'm trying to pick apart a string, mainly the price on an Item on a vendor.
what I'm thinking is to split the string up from $, then search for the word Price: and take everything from the right side of that?
is there a simpler form? I can't seem to figure it out :)

Here's a couple routines I have that takes a string that's delimited by anything (in this example, it's delimited by "$") and splits it into substrings that can be addressed.

Code: [Select]
event property XXYYZZ
gosub TM_SplitString #PROPERTY $
gosub TM_GetIndex 1 ; 2nd line of text
if #RESULT = Blessed
  display This item is blessed!
stop

sub TM_SplitString
  namespace push
  namespace local PS
  namespace clear
  set !string %1
  set !delimiter %2
  set !cnt 0
  str pos !string !delimiter
  repeat
    if #STRRES = 0
      break
    set !temp #STRRES - 1
    str left !string !temp
    set !array . !cnt #STRRES
    set !cnt !cnt + 1
    set !temp !temp + 1
    str del !string 1 !temp
    set !string #STRRES
    str pos !string !delimiter
  until #STRRES = 0
  set #RESULT !cnt
  namespace pop
return #RESULT

sub TM_GetIndex
  namespace push
  namespace local PS
  set !index %1
  set #RESULT !array . !index
  namespace pop
return #RESULT

For your requirements, you'll want to find "price" on the 3rd line (or index 2).  Just delete the "Price:_" and you'll have the price.
Title: Re: Strings Drive my Crazy
Post by: Khameleon on March 06, 2009, 05:05:42 AM
Thanks TM, we got that part ironed out.

I'm not sure if I understand this next part correctly.
I've saved a list of Items from a vendor into a listbox, now I would like to save those items to a file to be accessed later.

Code: [Select]
Sub Save
gosub TM_FileSystem_CreateFileHandle NULL Save_VendorInventoryList
  namespace push
  namespace local TM_window_list_InventoryList

for %i 0 !list_ptr
    {
    gosub TM_FileSystem_SaveVariable NULL local std Save_VendorInventoryList list , %i
    }
gosub TM_FileSystem_SaveFile Save_VendorInventoryList c:\ , #CharName , InventoryList , .txt
namespace pop
Return
Title: Re: Strings Drive my Crazy
Post by: TrailMyx on March 06, 2009, 07:37:42 AM
Hmm, why aren't you using TM_SaveListToFile?  v1.22(of the list handler) has a method to save/load list items... ;)  No need to do it by hand.  However if you DO want to do it by hand, you can just take a look at both of those subs to see how it's done.
Title: Re: Strings Drive my Crazy
Post by: Cerveza on March 06, 2009, 07:52:57 AM
I like string cheese  :D
Title: Re: Strings Drive my Crazy
Post by: TrailMyx on March 06, 2009, 08:14:11 AM
I like string cheese  :D

Ohhh, man string cheese!!  That's good eats!
Title: Re: Strings Drive my Crazy
Post by: Khameleon on March 06, 2009, 09:55:48 AM
man, TM, I totaly forgot there was a listhandler saver. *Slaps Forehead*


I like Melted String Cheese.