Page 1 of 1

"fun with filters 2" the filter strikes back

Posted: Tue Aug 05, 2008 10:18 pm
by Betelgeuse
due to the nice response to my filter thread I am giving a little more advanced example (I am planning a more advanced example still but that will need some thought)

Code: Select all

(setq items (objGetItems gSource "*"))

;filter out things that can not be tranformed into other things
(setq items (filter items element (itmGetStaticData element "tranformable")))

;pick an item at random

(setq randomPick (item (shuffle items) 0))

;find what items it can be combined with

(setq items (filter items element (itmGetStaticData element (cat "startWith" (itmGetStaticData randomPick "prefixTransform")))))

;pick an random ending item

(setq randomEndPick (item (shuffle items) 0))

;get all the items
(setq allItems (itmGetTypes "*"))

;filter out all items that do not a result of this

(setq allItems (filter allItems element (itmGetStaticData (itmCreate element 1) (cat (itmGetStaticData randomPick "prefixTransform") (itmGetStaticData randomEndPick "postfixTransform"))))) 

;get random result

(setq result (item (shuffle allItems) 0))

the head enjineer at tinker station take a look at your cargo and says "hey i can take this [put name here] and [put second name] and i could make you this wonderful [result].

Code: Select all

;remove old items

(objRemoveItem gSource randomPick 1)
(objRemoveItem gSource randomEndPick 1)

;add new item
(objAddItem gSource (itmCreate result 1) 1)
warning this has no error checking so you have to add your own

Posted: Tue Aug 05, 2008 10:25 pm
by digdug
now let's mod all the items to add staticdata to them for the tinker station !

Posted: Tue Aug 05, 2008 11:00 pm
by Aury
:lol: lol, I was going back and adding in special tags to every weapon (like a standard laser was "etc...; single; laser1" then dual turbolaser is "...etc; multi2; laser2" etc...
I was planning on doing something similar w/ the code... :D

Posted: Wed Aug 06, 2008 4:47 pm
by Betelgeuse
oh don't use shuffle to get a random item from a list you can use random. I forgot about that aspect of random.