Jump to content

XML math???


Iceburg71

Recommended Posts

Struggling with this one..  I would like to be able to get the "mass" of an animal or zombie, and then be able to multiply that by a number that has a decimal (say .75).  But I don't want the output to have a decimal, just be a whole number.  I am really struggling with this for some reason today and my brain is mush.  

 

Creating new Zombies and Animals and would like to be able to do the following:

property name="SizeScale" value=".8"

property name="Mass" value=(mass of current zombie in game) * (SizeScale defined for new zombie in the line above)

 

Any help appreciated.

 

Link to comment
Share on other sites

I don't think this is currently possible. The reason why, depends upon what you're asking.

 

If you're asking whether you can do this with XPath, then I'm pretty sure the answer is "no," because you can't get values with XPath. It doesn't have variables, so it doesn't have any way to store a value. You can target the "Mass" value of the current zombie (using e.g. "/path/to/zombie/property[@name='Mass']/@value"), in order to set it, but you can't read its value.

 

If you're asking whether you can do this using XML - meaning, using all the functionality of 7D2D that can be specified with XML tags - then I'm pretty sure the answer is still "no." Simply put, TFP haven't coded a feature where you can directly access the value of property tags. You can access - and modify - cvars, but that's not the same thing. So, unless TFP created two cvars that map to the "Mass" property and the "SizeScale" property, there's no way to read these values.

 

That's not even considering the notion of converting a float to a decimal, though I'm not sure this is even needed in the case of the "Mass" value.

 

Having said all that - if you're creating new zombies or animals anyway, why not just do all of this yourself? The math isn't difficult - certainly not as difficult as learning XPath. :)

Link to comment
Share on other sites

Yeah,  I am not wanting to store the value anywhere, be able to pull the value from the object and do some math on it at the same time as setting it.

 

I was able to figure out a better way to add my animals to the groups with some functions like this:

    <append xpath="/entitygroups/entitygroup[descendant::entity[@name='animalDoe' and not(@prob='0.73' or @prob='1')]]">
        <entity name="animalIceburgBabyDeer" />
    </append>
    <append xpath="/entitygroups/entitygroup[descendant::entity[@name='animalDoe' and @prob='0.73']]">
        <entity name="animalIceburgBabyDeer" prob="0.73" />
    </append>
    <append xpath="/entitygroups/entitygroup[descendant::entity[@name='animalDoe' and @prob='1']]">
        <entity name="animalIceburgBabyDeer" prob="1" />
    </append>
 

With this method, I just have to know what the probabilities are for the animalDoe (which is a quick search with notepad++), and this adds the BabyDeer in all the same spots as the "mom" in the entire entitygroups.xml file.  If the probabilities change, it is a quick change and the mod is back in business.  I don't care what the Funpimps do to any biome names, game stages, zombie groups, animal groups, etc.  I just does not matter to me anymore with the way I am adding my entities to the entitygroups.xml file.  VERY future proof.

 

The current mod I am working on is around 700 lines of XML.  It includes (currently, but growing) about 30 entities.  Each entity has between 8-12 attributes to set and that could change if the Funpimps decide to change the defaults on an entity.  So doing the math on currently about 300 entries in the .xml file and saving it correctly with no typos is really becoming a chore.  If I can find a way to automate the process using math, and being able to reference the current vanilla entity, then my life becomes a LOT easier and the chances of a change in the OEM code causing an issue becomes much less.  Also reduces the chance of me releasing a mod with an error somewhere that I have to go back and fix.

 

I will keep poking around with it.  May stumble across a way to do it.

Link to comment
Share on other sites

2 hours ago, Iceburg71 said:

Yeah,  I am not wanting to store the value anywhere, be able to pull the value from the object and do some math on it at the same time as setting it.

 

I was able to figure out a better way to add my animals to the groups with some functions like this:

    


    <append xpath="/entitygroups/entitygroup[descendant::entity[@name='animalDoe' and @prob='0.73']]">
        <entity name="animalIceburgBabyDeer" prob="0.73" />
    </append>
    <append xpath="/entitygroups/entitygroup[descendant::entity[@name='animalDoe' and @prob='1']]">
        <entity name="animalIceburgBabyDeer" prob="1" />
    </append>
 

With this method, I just have to know what the probabilities are for the animalDoe (which is a quick search with notepad++), and this adds the BabyDeer in all the same spots as the "mom" in the entire entitygroups.xml file.  If the probabilities change, it is a quick change and the mod is back in business.  I don't care what the Funpimps do to any biome names, game stages, zombie groups, animal groups, etc.  I just does not matter to me anymore with the way I am adding my entities to the entitygroups.xml file.  VERY future proof.

 

The current mod I am working on is around 700 lines of XML.  It includes (currently, but growing) about 30 entities.  Each entity has between 8-12 attributes to set and that could change if the Funpimps decide to change the defaults on an entity.  So doing the math on currently about 300 entries in the .xml file and saving it correctly with no typos is really becoming a chore.  If I can find a way to automate the process using math, and being able to reference the current vanilla entity, then my life becomes a LOT easier and the chances of a change in the OEM code causing an issue becomes much less.  Also reduces the chance of me releasing a mod with an error somewhere that I have to go back and fix.

 

I will keep poking around with it.  May stumble across a way to do it.

 

Ah, targeting probabilities. I ran into this issue myself when trying to add custom zombies, and having their probabilities match those of existing zombies. I could not find a way to do it other than, basically, what you're doing now. It gets even more hairy when there are a ton of different possible probability values (like for zombieBoe).

 

In my case, I just looked for the most common probabilities, for each of the zombie types I was replacing, and matched those. For the rest I didn't worry about it and added a "midrange" probability value.

 

In your particular example, "animalDoe" only appears once in the entire file (in the "WildGameForest" group), so I wouldn't even worry about the probabilities for that one.

 

Personally, I also wouldn't try to be forward-compatible with future 7D2D alphas. You'll probably have to tweak it when a new alpha comes out, no matter what. As an example, look at the probabilities in the "EnemyAnimals" groups. Those have probabilities that are values like 10, 20, 30, 48... Before this alpha, TFP used probabilities between 0 and 1, so a previous mod would need to be updated anyway.

 

Also - about XPath - when I say "store" I don't mean "write to the XML." I mean "store in memory." You can't "pull the value from the object" because there's no place to pull it to.

 

EDIT: Before this edit, I previously said something here about how XPath has no notion of numbers. It turns out I was wrong. XPath actually does include functions that operate on numbers.

 

However - I have no idea if XPath, as implemented in 7D2D, supports those functions.

 

Here's an example. Say you want to target probabilities between 0.2 and 0.3:

<insertAfter xpath="/entitygroups/entitygroup/entity[@name='animalDoe' and @prob >= 0.2 and @prob <= 0.3)]">
  <entity name="animalIceburgBabyDeer" prob="2.5" />
</insertAfter>

 

As I said, I have no Earthly idea if those operators are supported in 7D2D. You could try it and find out.

 

EDIT 2: ...Thinking about it - 7D2D probably does not support these particular operators, because an XML parser will see ">" and think it's the end of the XML tag. But they do exist in XPath, so maybe TFP have some other function that is equivalent?

 

(I learned about these operators by examining documentation about XPath in general - but XPath is usually used in JavaScript, which is totally different.)

Link to comment
Share on other sites

You can't just include an xpath string in the attribute of an XML tag and expect it to work. 7D2D only supports xpath strings in the "xpath" attribute of a node that represents an append/replace/insert command. And those commands are only supported in the specific XML files in the Mods folder.

 

It's confusing because TFP implemented XPath using the XML language (and not, say, JavaScript or C#). They had good reason, but it can be hard to separate the two.

Link to comment
Share on other sites

Can't offer any insight on whether XML can do the "mass" calculation you want or not, just wanted to point out that mass would scale differently than proportions in real life.  See the square-cube law for more info. If I understand it correctly, scaling the size of a creature to .8 would reduce its area to .64 and mass to .512 of the original values (the scaling factor squared and cubed, respectively). I know this doesn't help you unless you actually get the XMLs handling it automatically, though, and I wish you luck with that.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...