PDA

View Full Version : Parsing XML Data


Sims MX
19th Aug 2011, 04:32 AM
Hello!

I'm making a Hypochondriac trait for my game and I would like to create a list of possible diseases for my Sim. I made an XML for this, it looks something like this: <Disease>
<Name>SkinCancer</Name>
<Desc>SkinCancerDesc</Desc>
<Chance>0.2</Chance>
<WeighingTraits>HatesOutdoors</WeighingTraits>
<LighteningTraits>LovesTheOutdoors</LighteningTraits>
</Disease>Basically it means that Hypochondriac Sims have 20% of believing they suffer from Skin Cancer. This chance is increased to 30% if they Hate the Outdoors, or it is decreased to 10% if they Love the Outdoors.

When Sims go out and the "kChangedInsideOutsideStatus" event is triggered, I call an event delegate function. This is supposed to add the "Feeling Sick" moodlet. public static ListenerAction ChangedInsideOutsideStatus(Event e)
{
Sim sim = e.Actor as Sim;
if (sim != null && sim.HasTrait((TraitNames)(Hypochondriac)) && sim.IsOutside && !OccultVampire.IsNightTime())
{
if (RandomUtil.RandomChance01(TraitFunctions.GetChance(ActorSystems.TraitFunctions.HypochondriacTraitDisease.SkinCancer, sim))
{
sim.BuffManager.AddElement((ulong)(FeelingSick), Origin.FromTheSun);
}
}
return ListenerAction.Keep;
}As you can see it is a simple event listener. However, you may notice that I have a "GetChance" method. This, as it name implies, is supposed to get the chance for my disease.

I made a method to parse the data from my XML and then I made this "GetChance" method. It looks like this: public static float GetChance(TraitFunctions.HypochondriacTraitDisease disease, Sim sim)
{
float chance = 0f;
for (int i = 0; i < sDiseases.Count; i++)
{
DiseaseData data = sDiseases[i];
if (data.Disease == disease)
{
chance = data.Chance;
foreach(TraitNames trait in data.WeighingTraits)
{
if (sim.HasTrait(trait))
{
chance += 0.1f;
}
}
foreach(TraitNames trait in data.LighteningTraits)
{
if (sim.HasTrait(trait))
{
chance -= 0.1f;
}
}
}
}
return chance;
}The problem is that my Sims don't get any moodlets at all.

Help would be appreciated, thanks!

Buzzler
19th Aug 2011, 07:18 AM
public static ListenerAction ChangedInsideOutsideStatus(Event e);I'd suggest to start here. Add a couple debugging notifications and check whether your callback gets actually called and what is passed to it.

Sims MX
25th Aug 2011, 01:10 AM
It works now! I spent several days looking at the code and making tests and I couldn't realize my mistake. It was so obvious! I had a "ParseData" method, but I didn't have a "Load" method, so my XML was never loaded by the game. I feel so dumb :P, thanks for the help anyways!

Buzzler
25th Aug 2011, 06:48 AM
I had a "ParseData" method, but I didn't have a "Load" method, so my XML was never loaded by the game.Oh, shoot, and I actually thought of asking about that, but then decided not to. "Is there fuel in the tank?" and stuff... :p