PDA

View Full Version : GameObj stuff



nunye
11-03-2016, 11:24 AM
How would I do the following using GameObj.contents so I call on the gameobj-data file? I just want to see if my container has any furs so I can sell them all at one time instead of individually. I get how to do it individually, but I'm missing something here.



fur = ['fur', 'skin', 'hide'[
contents = result.scan(/\b(?:#{fur.join('|')})(?= and an? |,|\.)/)
unless contents.nil? or contents.empty?
start_script 'go2', [ 'furrier' ]


Thanks!

Ososis
11-03-2016, 04:09 PM
Why not just sell your bag at the furrier each time instead of skin checking?

Donquix
11-03-2016, 05:46 PM
use the "type" game object property.

something like:
skins = GameObj['cloak'].contents.select { |item| item.type == 'herb' }
skins.each { |skin| do some shit with skin }

select will return a hash of all the objects of type "herb", furs / skins / etc. should be skin. You could also iterate over all the conents and only execute whenever item.type == 'blah', i like select I think it ends up cleaner. more than one way to skin a ruby.

nunye
11-03-2016, 07:59 PM
Why go to the furrier if I don't have any furs?

nunye
11-03-2016, 08:47 PM
I'm not sure that will work for what I want. Here's what I ended up with:


skins = GameObj[Vars.lootsack].contents.select { |item| item.type == 'fur' }
skins.each { |skin|
start_script("go2", [ "furrier", '_disable_confirm_' ])
wait_while { running?("go2")}
}

Since I had three skins in my lootsack it tried to take to the furrier three times. So, it's close, but not quite. I basically just want it to do this:


"Yes skins?" Do this!
"No skins?" Do nothing!

Donquix
11-03-2016, 09:11 PM
this is less problems with lich and more problems with ruby and basic programming logic. I'd reccomend doing some intro to ruby coding things online.

you'd need something like

if skins.length > 0
start_script("go2", [ "furrier", '_disable_confirm_' ])
skins.each { |skin|
selling shit here
}
end

nunye
11-11-2016, 09:36 AM
It ended up being pretty simple once I sat down and thought about it.


contents=GameObj[Vars.skinsack].contents.find {|item| item.type.include? 'fur'}
if contents
echo "Yes, you got some, do something with it!"
else
echo "All out!"
end

Tillmen
11-11-2016, 01:15 PM
You could also use GameObj[Vars.skinsack].contents.any? { |o| o.type.include? 'fur'}
.any? returns true/false, and .find either returns the thing it found or nil. Unless the thing you want it to find is nil or false, then you get the same results with either method. Still, something bugs me about returning the found object and not using it.

nunye
11-11-2016, 02:18 PM
You could also use GameObj[Vars.skinsack].contents.any? { |o| o.type.include? 'fur'}
.any? returns true/false, and .find either returns the thing it found or nil. Unless the thing you want it to find is nil or false, then you get the same results with either method. Still, something bugs me about returning the found object and not using it.

I don't know what you mean (about not using it).

Gnomad
11-11-2016, 03:42 PM
I don't know what you mean (about not using it).

Your contents variable isn't Boolean (true/false), it's an actual item or nil (nothing found).

You're finding the first fur in your inventory and not doing anything with it but still storing it in a variable. It works both ways, but it's not as elegant this way. And if you code in a more strictly-typed language, doing it this way wouldn't work as nicely.

nunye
11-11-2016, 03:47 PM
Thanks, I got it. It makes perfect sense, and I learned something new!