Spawning objects at a certain time from a txt file
How would I go about interpreting a .txt file which holds an object to be spawned at a specific time?
For example the list of objects in the text file would be in the format of:
time,propertyA,propertyB,propertyC,propertyD
How would I assign these properties to the object and have it spawn at a certain time(in ms)?
So far I can read the file text, but I'm unsure how to derive anything from it.
I haven't found any reliable tutorials on spawning objects at a specific time, with specific properties, using a text file.
Posted Mar 11, 2019, 4:43 AM UTC
Text file is not a very good meta date format.
Try use XML file.
Use serialization to create the necessary objects.
Example Enemys list :
public class Enemys
{
public List<Enemy> EnemyList = new List<Enemy>();
public class Enemy
{
public int id = 0;
[XmlAttribute]
public int armor = 0;
[XmlAttribute]
public int health = 0;
[XmlAttribute]
public int speed = 0;
Example Enemy XML :
<?xml version="1.0" encoding="utf-8"?> <Enemys > <EnemyList> <Enemy id="0" armor="100" health="100" speed="1"/> <Enemy id="1" armor="100" health="100" speed="1" /> </EnemyList> </Enemys>
Load to Game:
XmlSerializer xs = new XmlSerializer(typeof(Enemys));
Stream readFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
Enemys enemys = (Enemys)xs.Deserialize(readFileStream);
readFileStream.Close();
The file I'm trying to read is not xml.
They're saying that you should probably use XML instead of a txt file. And I agree. I personally prefer Json, but to each their own.
Mind if I ask why you're trying to do in txt format?
Because I'm reading from a specific file format