Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. 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.
  2.  
  3. STEP 1: The mod manager.
  4.  
  5. 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.
  6.  
  7. Imports
  8.  
  9. 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.
  10.  
  11. Capture
  12.  
  13. Time to create the method for loading the xml.
  14.  
  15. XML loading method.
  16.  
  17. Now that we have a way of loading a single xml file we need a way to get the data out of it.
  18.  
  19. Capture Capture1
  20.  
  21. 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.
  22.  
  23. 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.
  24.  
  25. Capture
  26.  
  27. 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.
  28.  
  29. Capture
  30.  
  31. The scan files method uses recursion to look through the folders and find the files the have an xml line ending.
  32.  
  33. Capture
  34.  
  35. 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.
  36.  
  37. Capture
  38.  
  39. 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.
  40.  
  41. Capture
  42.  
  43. STEP 2: The Parser
  44.  
  45. 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.
  46.  
  47. Capture
  48.  
  49. As seen above, I get the xml and run it through a method.
  50.  
  51. 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.
  52.  
  53. Capture
  54.  
  55. Closer Text.
  56.  
  57. 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