Welcome to
Mod The Sims
Online: 2076
News:
Have an account? Sign in:
pass:
If you don't have an account, why not sign up now? It's free!
Other sites: SimsWiki
Reply  Replies: 3 (Who?), Viewed: 1132 times.
Search this Thread
Old 14th Jun 2012, 03:52 AM How to make a list of objects with certain constrain? #1
Cherry92
Original Poster

Lab Assistant

Join Date: Jan 2006
Posts: 103
Thanks: 4830 in 10 Posts
9 Achievements


Code:
private GameObject GetRandomObject() {
	if (mObjects == null) {
		mObjects = new List<GameObject>(Sims3.Gameplay.Queries.GetObjects<GameObject>(base.Actor.LotCurrent));
		mObjects.Remove(base.Actor);
	}
	return RandomUtil.GetRandomObjectFromList<GameObject>(mObjects);
}

I'm using the above code to select random object from current lot,
but it's a little buggy since plumbbobs and skillmeters are included,
also I want to fix the range of objects to the same floor with the actor..

Is there any way to modify the method to get my desired results?
I've think of two way to do, but it failed or I can't think of how to do.




For selecting objects from the same floor as the actor:
1) Calculate Y-component of position vector by: obj.Y - obj.(height from floor)
and compare this with actor.Y, but even allowing an epsilon for error doesn't work,

2) Test if the route is routable before I really route to the object,
I've no idea how I could do this, and seems there's no relevant method...
or did I overlooked something?



And for not selecting plumbbobs and skill meter:
Code:
foreach (GameObject obj in mObjects) {
	if (obj is Plumbbob || obj is SkillMeter)
		mObjects.Remove(obj);
}
But unfortunately, this just remove EVERYTHING in mObjects
Last edited by Cherry92 : 14th Jun 2012 at 06:19 AM. Reason: typing mistake
Old 14th Jun 2012, 09:14 AM
MDM
This message has been deleted by MDM. Reason: See post below
Old 14th Jun 2012, 10:38 AM #2
Buzzler
1978 gallons of pancake batter



Join Date: May 2006
Posts: 2,211
Thanks: 28038 in 74 Posts
22 Achievements

View My Journal


Quote:
Originally Posted by Cherry92
And for not selecting plumbbobs and skill meter: [...] But unfortunately, this just remove EVERYTHING in mObjects
That will actually throw an exception. You can't alter a collection while you're iterating through it with a foreach loop. Use a while loop instead.

Or use FindAll and a Predicate:

(new List<GameObject>(Sims3.Gameplay.Queries.GetObjects<GameObject>(base.Actor.LotCurrent))).FindAll(obj => !(obj is PlumbBob) && !(obj is SkillMeter));

Robot Armed With Down Comforter Levels Apartment Building, Holds Mayor Hostage.
Old 14th Jun 2012, 11:04 AM #3
MDM
Lab Assistant

Join Date: Nov 2004
Posts: 195
Thanks: 2622 in 7 Posts
7 Achievements


Ahhh, the power of Lambda expressions, I'm currently reading about those and they're cool, the problem is trying to include them when I think about solutions but I'll get to it someday

Nothing's real. Nothing's unreal either.
The frontier between true and untrue is a shady fuzzy line.
Destiny, or maybe the long flight's time-span, shall decide the issue.
Old 14th Jun 2012, 04:38 PM #4
Cherry92
Original Poster

Lab Assistant

Join Date: Jan 2006
Posts: 103
Thanks: 4830 in 10 Posts
9 Achievements


Quote:
Originally Posted by Buzzler
That will actually throw an exception. You can't alter a collection while you're iterating through it with a foreach loop. Use a while loop instead.

Or use FindAll and a Predicate:

(new List<GameObject>(Sims3.Gameplay.Queries.GetObjects<GameObject>(base.Actor.LotCurrent))).FindAll(obj => !(obj is PlumbBob) && !(obj is SkillMeter));

It's working, thanks.
There is too much to learn


And the problem of getting objects from the same floor is also solved,
getting the value of obj.PositionOnFloor.y would be sufficient
Last edited by Cherry92 : 14th Jun 2012 at 05:18 PM.
Reply


Section jump:


Powered by MariaDB Some icons by http://dryicons.com.