Read txt into string array, recognize as commands with arguments


I’m making a game with a friend, inspired by an old game called Colobot.
In our game, you will have 2 teams, each with 10 tanks.
These tanks can drive, turn, aim, shoot and scan for targets, but do nothing on their own, nor do they react to input.

The goal in the game is to write a (very) basic script in a .txt file, which could look something like this:









a tank executing that simple script will do only one at a time. For example, after move(1) is a fire command. The tank would not fire untill the move(1) command is finished.

But there is one problem; this is the first time either of us have done anything with reading a text file, and recognizing commands(and their arguments).

So my questions are, how do i read seperate lines of a txt and put them in a string array,
and, how do i recognize those as commands, with arguments?

the ifs might be a challenge too, but i’m mostly interested in the two points above, hoping i’ll manage to figure the rest out myself.

(PS: i’m thinking of suggesting the name Codeception to my friend :D)

I’m not sure this is a topic that can be sufficiently explained in a single Unity Answers post. Just reading a text file and breaking it into individual parts is easy (using the C# string functions or Regular Expressions), but you’re also looking at various tasks that comprise (even simple) compiler design, like scanning, parsing, tokenization etc.

If you have iTunes University, you can search for “Introduction to Compiler Construction” from the University of Salzburg for an introduction to the problem. I’m sure there’s other web resources along the same lines, as well.
Alternatively, you might be able to find and use a scripting module/plugin for the Unity Engine - but if one exists I’m not aware of it.