Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
So I'm making a bot for Super Smash Brothers in EE, and it's faaar from done, but there's one problem I have with saving maps (and it can save and load individual maps), and that is that it won't save any special blocks I place.
The code I have for saving maps is:
static void SaveMap(string Filename)
{
string path = Environment.CurrentDirectory + @"\" + Filename + ".txt";
StringBuilder sb = new StringBuilder();
foreach (Block b in blockList)
{
if (b.x > 32 && b.x < 67 && b.y > 49 && b.y < 75)
{
sb.Append(b.l).Append("-").Append(b.x).Append("-").Append(b.y).Append("-").Append(b.bid).Append(",");
}
}
File.WriteAllText(path, sb.ToString());
Say("Done saving! Map saved as \"" + Filename + "\".");
}
And there's a second problem I experienced: it never seems to say the last line. Does that mean it will continue saving the blocks in that area forever? And how do I fix that then?
ERMAHGERD I AM THERE
Offline
So I'm making a bot for Super Smash Brothers in EE, and it's faaar from done, but there's one problem I have with saving maps (and it can save and load individual maps), and that is that it won't save any special blocks I place.
The code I have for saving maps is:
static void SaveMap(string Filename) { string path = Environment.CurrentDirectory + @"\" + Filename + ".txt"; StringBuilder sb = new StringBuilder(); foreach (Block b in blockList) { if (b.x > 32 && b.x < 67 && b.y > 49 && b.y < 75) { sb.Append(b.l).Append("-").Append(b.x).Append("-").Append(b.y).Append("-").Append(b.bid).Append(","); } } File.WriteAllText(path, sb.ToString()); Say("Done saving! Map saved as \"" + Filename + "\"."); }
And there's a second problem I experienced: it never seems to say the last line. Does that mean it will continue saving the blocks in that area forever? And how do I fix that then?
I suggest making your Block object serializable.
That way you can make a List/array of your Block objects and save/load the List/array directly.
Code I use for serializable object saving/loading (You'll have to make a quick Google on how to serialize your objects, it's real easy):
http://pastebin.com/jfXQem8N
The code is put in a class, but obviously you can always take the methods out and place them elsewhere.
Offline
I have absolutely no idea how to do it. I'm just a programming nub, and whenever I find something that could help, I either don't know which things to replace, or where to place it (or even what it means).
ERMAHGERD I AM THERE
Offline
I'm just going to paste a short tutorial with code I have:
If I'm correct, what you're trying to do is safe a Block object
example:
Now what you can do to safe this object, is make it serializable by adding "[Serializable()]" in front of the class, giving you (bold is what is added):
Now that we got our Block object serializable, we can save and load it with the code I gave you in the code snippet:
http://pastebin.com/jfXQem8N
This code snippet consists out of a class with 2 functions/methods:
"save<T>" and "load<T>"
You can take the methods out of the code snippet and place them wherever you'd like, just like any other method.
Now what we're going to do is actually save and load something.
First we read our world and put the found blocks in Block objects (like what you have already managed to do from the looks of your own code snippet (blockList)).
Here is how I assume blockList is initialized:
List<Block> blockList = new List<Block>();
And after that it's filled with Block objects
Now we got our list of Block objects. All that's left to do is save/load it!
The "T" in the methods' names mean that the type isn't defined, meaning any Object can be put here.
To save your List you just call the method in the following way:
save<Block>(blockList, path, fileName);
Obviously you'll first have to define "path" and "fileName".
Congratulations! You've saved your Block objects!
Now how to load them back in:
And then you just do with the read blocks whatever you want!
Hope it's clear now, just tell me if it's still not clear (I might answer in a PM though).
P.S. I personally often don't know how to use big code snippets from others too, which if why I personally always like to make things myself (the save/load functions I haven't made myself btw).
Offline
I prefer to add an object array for extra data and keep it null when using it unless extra data is needed.
public class Block
{
public int Layer;
public int X;
public int Y;
public int BlockID;
public object[] Args;
public Block(int layer = 0, int x = 0, int y = 0, int bid = 0, object[] args = null)
{
Layer = layer;
X = x;
Y = y;
BlockID = bid;
Args = args;
}
}
And JSON(Javascript object node) to save and load objects.
Offline
[ Started around 1732291562.4288 - Generated in 0.081 seconds, 13 queries executed - Memory usage: 1.45 MiB (Peak: 1.6 MiB) ]