Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using XML to handle data can be one way to handle modding into your games. It can be used to change the the damage stats on a weapon, or to add a new item to the game.
- STEP 1: The mod manager.
- The first step to making mods to have a something to manage them, so we we need to add the imports for handling the xml.
- Imports
- The next Thing I do is to create a class to handle using a single xml element. Now we need to create the variables we will be using.
- Capture
- Time to create the method for loading the xml.
- XML loading method.
- Now that we have a way of loading a single xml file we need a way to get the data out of it.
- Capture Capture1
- These to methods allow us to get the data in the form of string and float variables. There are other ways to parse it out, using various parsing methods, but we won't go that far in depth.
- Now it’s time to create the Mod Manager class. To start, we will need some variables. The variable we will be adding in is a List of XMLElements, which is the class we created earlier.
- Capture
- Now it is time to build the file scanner. Alternatively, you could manually input the file locations. The following method checks the files found by the scanner, then polls the mods contained in each file.
- Capture
- The scan files method uses recursion to look through the folders and find the files the have an xml line ending.
- Capture
- With the previous two methods, we now have our list loaded with xml files from our mods folder. Now we need the loading methods: One to load the xml and one to check if it has already been loaded, just in case you want to update the mods via console commands or something like that.
- Capture
- The following methods are used to get the xml strings and numbers for use, then the last one is more of a utility method which allows us to get the index of the xml with a bit more ease.
- Capture
- STEP 2: The Parser
- The next the thing we will have to do is parse the data so that we can use it for an item. For this part I will use an example from the game I am currently making.
- Capture
- As seen above, I get the xml and run it through a method.
- Here is a snippet of how it could work. I have the name going into the name variable while cycling through the nodes. It tests if the name equals “randName” and if it does it will called the random name generator I made for this.
- Capture
- Closer Text.
- Now you should be able to create a a mod manager with xml for your games.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement