Sign in to follow this  

Unity Creating a flexible parsing/scripting engine

Recommended Posts

I have a game that has many tokens, each with its own gametext. I need a way to process this gametext and allow additional tokens to be added later without hard-coding. Let's take a simple fireball as an example. The token's game text may read something like "Fireball does 3 dmg to target character". Seems simple, but the program has to understand what is targetable, damage type, how many targets, how much damage etc. So the token has a field that looks like this: ["direct", "Fireball", "fire", character, 1, 3] Which declares the name of the token is "Fireball" which does 3 points of direct fire damage to one character target. We create a damage object out of this that holds these attributes and then call the directDamage method:
	// Calculate damage to all targets
	public static void directDamage(Token source, Damage damage, ArrayList<Token> targets)
		Iterator<Token> it = targets.iterator();
		while (it.hasNext())
			processDamage(source, damage,;
	// Alter Hit Points
	private static void processDamage(Token source, Damage damage, Token target)
		int newHP = target.getAvatar().getHitPoints() - getDamage(source, damage, target.getDefense());
	// Determine how damage is affected by defense
	private static int getDamage(Token source, Damage damage, Defense defense)
		if (defense == null)
			return damage.getDamageNumber();
			// Determine if defense is against damage type
			if (defense.getDefenseType().equalsIgnoreCase(damage.getDamageType()))
				return 0; // assume immunity for now 
				return damage.getDamageNumber();

I can see additional parameters having to be added later but is this a reasonable start? I've never tried to code anything that has to be so flexible with the English language and I'm a bit unsure where to start.

Share this post

Link to post
Share on other sites
Maybe you could use, instead of that token, two objects, one with all the basic information that EVERY token has, or that you just know it won't need to be flexible, and another object with specific information about that token.

These two objects would be passed to a method that would handle all the basic information right there and would pass the object with the more specific information to a specific method to handle it.

If you use just one object you'd have to have lots of methods to handle all the types of tokens supported creating lots of duplicated code, with two, you have one central method to handle the common stuff, that by itself might even be enough for some simple tokens, and you have another set of methods to handle the rest, without much code duplication.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By Ahrakeen
      Hello our team aare making the game Neo arcana a logical crisis. and w are presently searching for some graphics people to help with the models for the game.
      we are using the setting of urban arcana and the game will be a strategic roleplaying game. in so we are in need of help with the graphics.
      if you interested to aiding us with your skills let us know. we are presently working on the prologue with the aim of finishing the story of some of the things that happened back then.
      to set up the story for the main game itself where tim is now trying to regainw hat he has lost back then. And manuever in the strange world that is hidden beneath the surface of the city.
      We aim with the prologue done turning it into a demo to get funding . so i hope to get more help with this.
    • By Hacktion Architects
      Hey guys me and my team have made our first game! Would be awesome if you guys could download, play it and let us know what you think!

      3. 2. 1. GO! Fly through the local school grounds with three other drones vying for the fastest time. Racing past the football fields, weaving in between pillars and squeezing through tight corridors, in Drozone speed is everything.
      Race through checkpoints while keeping your eyes out for power ups that give you a big short burst of speed, but be careful not to lose control!
      And if you're having problems completing the course you will want to grab the shield power up to double your health.
      Pick your drone and start racing, will you be able to beat our fastest lap time?
      Trailer here:
      Link to download:
      A game developed by a group of seven young indie devs, from Brisbane Australia, Drozone is focused on delivering the exhilaration of flying a drone in first person.
      The experience is built up around competition between players and seeing who can get the fastest time. Let us know what you’re fastest time is!
    • By Polycanic Studios

      Everybody's favorite hard hitting reality blood sport is back and is better than ever. Join your host Miss Midnight and enter the Graviators arena for a new and thrilling style of combat.
      Graviators is a 3rd person arena based brawler in which you can play online multiplayer and LAN multiplayer with up to 4 friends or test your skills in our single player mode. Choose your fighter, control your gravity and fight using each characters unique ranged and melee attacks. 

      Download now at: or watch the Trailer
      Graviators is currently released but will be receiving updates to make improvements and fix any issues so please bear with us! If you want to know more about what we are up to, follow us here for regular devlogs or check out our Facebook or Twitter for updates. 
      If you want to get in contact with us, please feel free to comment here, or send us a message on Facebook!
    • By INTwindwolf

      We are an indie game studio consisted of professional and friendly people. Additionally, we are a team of skilled artists and dedicated indie enthusiasts. Our current project is INT, developed on Unity Engine 5 for platforms Windows, Linux, and Mac.

      INT is a 3D Sci-fi RPG with a strong emphasis on story, role playing, and innovative RPG features such as randomized companions. The focus is on the journey through a war-torn world with fast-paced combat against hordes of enemies. The player must accomplish quests like a traditional RPG, complete objectives, and meet lively crew members who will aid in the player's survival. Throughout the game you can side and complete missions through criminal cartels, and the two major combatants, the UCE and ACP, of the Interstellar Civil War.
      Please note that all of our current positions are remote work. You will not be required to travel.
      For more information about us, follow the links listed below.
      INT Official website
      Steam Greenlight
      IndieDB page
      Also follow social media platforms for the latest news regarding our projects.
      We are looking for an Animator to join the Art team to create and polish animations for the game. You will be collaborating with fellow members of the team, and follow instructions from the Project Lead and the Animation team Lead in crafting smooth, flowing animations.
      As an Animator for this project, your duties would include:
      Create rigs to be used for animations. Skin 3D models to rigs. Contribute to constructive team discussions. Attend regular team meetings.  
      To be successful in this position, following requirements apply:
      Have working knowledge of 3D animation suites. Understand import/export requirements for Unity Engine integration. Excellent self-management skills. Excellent attention to detail. Excellent communication skills. Preferred requirement:
      Knowledge of the Unity Engine UMA character creation system would be an advantage.  
      This is the perfect opportunity to get into the game development industry. Being an Indie team we do not have the creative restrictions often imposed by publishers or other third parties. We are extremely conscientious of our work and continuously uphold a high level of quality throughout our project.
      We are unable to offer wages or per-item payments at this time. However revenue-sharing from crowd-funding is offered to team members who contribute 15-20 hours per week to company projects, as well as maintain constant communication and adhere to deadlines. Currently the crowd-funding campaign is scheduled for the year 2018. Your understanding is dearly appreciated.
      TO APPLY
      Please send your Cover Letter, CV, Portfolio (if applicable), and other relevant documents/information to this email:
      Thank you for your time! We look forward to hearing from you!
      John Shen
      HR Lead
      Starboard Games LLC
    • By KARTHI
      Now I am making 2d game in my home. I am so confused with the resolution.
      Please anyone help me to choose the resolution
  • Popular Now