Results 1 to 3 of 3

Thread: Why wont this work!?

  1. Default Why wont this work!?

    Okay.

    Preface: I know Gib has already done a box dropper in a similar thread. I stole some of the logic from it and I know it does the job. However I'm trying to learn how .scan and other things work so, here I am, trying to hack some of the logic from Gib's script and another script so it actually scans the contents of a container and empties anything in the container that is defined in an array.

    The problem: For some reason it works awesome, up until there is only 1 of the items in my item array and then it wont take out the last item. Pointers as to why, how else to accomplish this, or if someone could actually explain whats going on I would be extremely grateful. (Learning to scan a containers contents would be really useful)

    The definition:

    Code:
    def boxdrop
    
    fput "drop right" if checkright =~ /(?:strong)?box|coffer|chest|trunk/
    fput "stow right" if checkright
    fput "drop left" if checkleft =~ /(?:strong)?box|coffer|chest|trunk/
    fput "stow left" if checkleft
    boxdb = ["coffer", "chest", "strongbox", "trunk", "box"]
    fput "turn #{checkname} disk"
    
    	$boxcont.split(',').each { |boxcont|
    		fput("look in my #{boxcont}").scan(/\b(?:#{boxdb.join('|')})(?=,|\.)/).each { |box|
    			fput "take my #{box} from my #{boxcont}"
    			fput "drop my #{box}"
    			sleep 0.15
    			fput "drop my #{box}" if(checkright(box) or checkleft(box))
    		}	
    	}
    end

  2. Default

    Got it to work. I think.
    Last edited by pabstblueribbon; 06-17-2009 at 12:23 PM.

  3. #3
    Join Date
    Nov 2004
    Location
    Upstate NY
    Posts
    428

    Default

    Since you asked, check out http://www.ruby-doc.org/docs/Program...ml#String.scan for details on how scan works.

    I'm not sure if it's still available with Tillmen's version, but it probably is -- String#split_as_list is what I always used in my own scripts, if memory serves. The implementation from my "lich-lib.rb" file, if you're curious. All the other methods used are standard Ruby fare, you can find them in the documentation I linked above:

    Code:
    class String
       def split_as_list
          string = self.sub(/^You (?:also see|notice) |^In the .+ you see /, ',')
          string.sub('.','').sub(/ and (an?|some|the)/, ', \1').split(',').reject { |str|
             str.strip.empty?
          }.collect { |str| str.lstrip }
       end
    end
    In a nutshell, it first replaces the "In the thingie you see" part with a comma. Then it snips out the period. That leaves something like ",a coin, a rock and a stick" as the string. Then it replaces the "and a" part of the string with another comma, leaving ",a coin, a rock, a stick" as the string. Then it splits the string up into an array of [ "", "a coin", "a rock", "a stick" ]. Then it rejects any elements that are empty strings (the first one is an empty string, because we've placed "In the thingie you see" with a comma -- fuck if I know why, but that's how I decided to do it all that time ago it seems.) Then it collects all remaining values after it calls String#lstrip on them (stands for "left strip" -- strips any whitespace off the left side of the string.) Then, since Ruby is Ruby, the result of that last collect method gets returned as the result of someString.split_as_list.

    Hope that helps.
    Last edited by Shaelun; 07-10-2009 at 03:23 PM.
    I visualize a time when we will be to robots what dogs are to humans, and I'm rooting for the machines. -- Claude Shannon

Similar Threads

  1. Game wont run
    By Jennyfer in forum PsiNet
    Replies: 10
    Last Post: 12-13-2010, 11:52 AM
  2. Lich wont install
    By Jennyfer in forum The Lich Project
    Replies: 2
    Last Post: 12-07-2010, 04:56 AM
  3. Psinet wont install
    By shadow34 in forum PsiNet
    Replies: 4
    Last Post: 02-19-2010, 10:10 PM
  4. game wont let me connect...
    By Holybane in forum General Gemstone
    Replies: 0
    Last Post: 08-05-2009, 02:44 PM
  5. Changed FE, now scripts wont work
    By stonegonad in forum Scripting Discussion
    Replies: 12
    Last Post: 08-26-2005, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •