Smider den på engelsk da jeg har postet på 4-5 andre engelske forummer
I have been ripping my hair out because I cant find a solution.
I got it all working, but now I must format more text
I got a new text that has sections like this:
1
0 33 10 85 162 95 168 -1 5 //Bull Fighter
1 29 30 40 113 45 116 -1 3 //Hound
2 41 5 126 160 125 161 -1 2 //Budge Dragon
3 38 5 106 161 111 160 -1 2 //Spider
4 38 5 106 161 111 160 -1 2 //Elite Bull Fighter
6 38 5 106 161 111 160 -1 2 //Lich
7 38 5 106 161 111 160 -1 2 //Giant
14 38 5 106 161 111 160 -1 2 //Skeleton Warrior
end
0
275 33 10 85 162 95 168 -1 5 //Test 1 Section 2
275 29 30 40 113 45 116 -1 3 //Test 2 Section 2
275 41 5 126 160 125 161 -1 2 //Test 3 Section 2
275 38 5 106 161 111 160 -1 2 //Test 4 Section 2
end
Now I changed my script so it reads the values from this script, and I changed the forward button so it jumps into new sections
But I just cant seem to figure out how to jump back to a section
This is the code that I use to go foward into a section:
if (pieces[0] == "end")
{
curRec += 2;
displayLine(curRec);
}
else
{
Here is all my code:
// Displays the line in the arraylist
public void displayLine(int linenumber)
{
// If the line number is in the range of total values
if ((linenumber >= 0) && (linenumber < lines.Count))
{
// Get the string out of the arraylist
String line = (String)lines[linenumber];
// Split it into various pieces on the space
String[] pieces = line.Split('\t');
if (pieces[0] == "end")
{
curRec += 2;
displayLine(curRec);
}
else
{
txtID.Text = pieces[0];
txtMap.Text = pieces[1];
txtMoving.Text = pieces[2];
txtXStart.Text = pieces[3];
txtYStart.Text = pieces[4];
txtXEnd.Text = pieces[5];
txtYEnd.Text = pieces[6];
txtDirection.Text = pieces[7];
txtCount.Text = pieces[8];
txtComment.Text = pieces[9];
mobImage.ImageLocation = "D:/images/" + pieces[0] + ".jpg";
}
}
}
// Arraylist to hold all lines of the file.
ArrayList lines = new ArrayList(100);
// Pointer variable to point to active record
int curRec = 0;
// Loading data and reading txt file
public void Form1_Load(object sender, EventArgs e)
{
// Open the data file
StreamReader f = new StreamReader(new FileStream(@"D:\monstersetbase.txt", FileMode.Open));
String curLine;
// Read in the data line by line and add it to our ArrayList
while ((curLine = f.ReadLine()) != null)
{
lines.Add(curLine);
}
// Close
f.Close();
// Add one so it will not crash
curRec += 1;
// Display first line
displayLine(curRec);
}
private void nxtButton_Click_1(object sender, EventArgs e)
{
if (curRec < lines.Count - 1)
{
curRec += 1;
displayLine(curRec);
prvButton.Enabled = true;
}
}
private void prvButton_Click_1(object sender, EventArgs e)
{
if (curRec == 2)
{
prvButton.Enabled = false;
}
if (curRec > 0)
{
curRec -= 1;
displayLine(curRec);
}
}
Portfolio: http://dumpen.dk