-
May 21st, 2015, 11:09 PM
#1
Thread Starter
Registered User
Colour Saving isn't working D:
Hey guys,
I was trying to save colour on a text file for four players and it worked. But then when trying to reload the colours, it only showed the colours for the first two players and the other two remained the default black. Then if I saved the game again a second time after loading it, only the colour of player 1 showed and then the one after that player 1 was black. I can't seem to find a mistake in the code and was wondering if you guys could help.
Cheers,
David of Davids
Code:
Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
Dim objgame As New System.IO.StreamWriter("C:\game.txt")
objgame.WriteLine(Player1Colour.ToArgb.ToString)
objgame.WriteLine(Player2Colour.ToArgb.ToString)
objgame.WriteLine(Player3Colour.ToArgb.ToString)
objgame.WriteLine(Player4Colour.ToArgb.ToString)
Private Sub LoadToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadToolStripMenuItem.Click
Dim objgame As New System.IO.StreamReader("C:\game.txt")
Dim templine As String
Dim Colour1 As Integer
templine = objgame.ReadLine()
If Integer.TryParse(objgame.ReadLine, Colour1) Then
Player1Colour = Color.FromArgb(Colour1)
End If
Dim Colour2 As Integer
templine = objgame.ReadLine()
If Integer.TryParse(objgame.ReadLine, Colour2) Then
Player2Colour = Color.FromArgb(Colour2)
End If
Dim Colour3 As Integer
templine = objgame.ReadLine()
If Integer.TryParse(objgame.ReadLine, Colour3) Then
Player3Colour = Color.FromArgb(Colour3)
End If
Dim Colour4 As Integer
templine = objgame.ReadLine()
If Integer.TryParse(objgame.ReadLine, Colour4) Then
Player4Colour = Color.FromArgb(Colour4)
End If
objgame.Close()
lblplayer1.ForeColor = Player1Colour
lblplayer1name.ForeColor = Player1Colour
btnroll1.ForeColor = Player1Colour
picPlayer1.BackColor = Player1Colour
lblplayer2.ForeColor = Player2Colour
lblplayer2name.ForeColor = Player2Colour
btnroll2.ForeColor = Player2Colour
picPlayer2.BackColor = Player2Colour
lblplayer3.ForeColor = Player3Colour
lblplayer3name.ForeColor = Player3Colour
btnroll3.ForeColor = Player3Colour
picPlayer3.BackColor = Player3Colour
lblplayer4.ForeColor = Player4Colour
lblplayer4name.ForeColor = Player4Colour
btnroll4.ForeColor = Player4Colour
picPlayer4.BackColor = Player4Colour
-
May 22nd, 2015, 04:22 AM
#2
Re: Colour Saving isn't working D:
Hey U53r N4m3, welcome to the Forum.
Every time you assign a colour to a player, you read 2 colours from your file.
Code:
Private Sub LoadToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadToolStripMenuItem.Click
Dim objgame As New System.IO.StreamReader("C:\game.txt")
Dim templine As String
Dim Colour1 As Integer
templine = objgame.ReadLine()
If Integer.TryParse(objgame.ReadLine, Colour1) Then
Player1Colour = Color.FromArgb(Colour1)
End If
' etc
Just substitute the second objgame.ReadLine with templine for each colour you read.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|