asf14
April 28th, 2010, 10:23 PM
Hello everyone,
i've created a dance mat game similar to Dance Dance Revolution. It has 4 arrows and when no step is taken it's a binary value 1111. When the up arrow is stepped on the binary value is 1110. I'm having problems with my scoring guide. I'm using streamwriter and streamreader to record the time stamp and the binary value of each step taken and once the game is done I have the file display the timestamps and the binary values. For right now I just want it to add one point for whenever it registers a step taken. This is the code I have that records the timestamp and the binary value. lblBitValue is the value that changes from a 1 to 0 binary.
Private Sub tmrReadInputs_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrReadInputs.Tick
Dim I As Short
Dim ULStat As MccDaq.ErrorInfo
Dim DataValue As UInt16
tmrReadInputs.Stop()
' read FirstPortA digital input and display
' Parameters:
' PortNum :the input port
' DataValue :the value read from the port
ULStat = DaqBoard.DIn(PortNum, DataValue)
If ULStat.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop
' display the value collected from the port
lblPortRead.Text = DataValue.ToString("0")
' parse DataValue into bit values to indicate on/off status
For I = 0 To 3
If (Convert.ToInt32(DataValue) And CInt((2 ^ I))) <> 0 Then
lblBitVal(I).Text = "1" 'NO STEP TAKEN
Else
lblBitVal(I).Text = "0" 'STEP TAKEN
TextBox1.Text = Trim(Format(Now, "hh:mm:ss tt "))
Dim GameFile As New System.IO.StreamWriter("C:\SavedGame.txt", OnGoingGame)
GameFile.WriteLine(TextBox1.Text & DataValue)
GameFile.Close()
OnGoingGame = True
End If
Next I
tmrReadInputs.Start()
End Sub
For the Scoring form I have the following:
Public Class Score
Public lblBitVal As System.Windows.Forms.Label()
Const PortNum As MccDaq.DigitalPortType = MccDaq.DigitalPortType.FirstPortA ' set port to use
Private DaqBoard As MccDaq.MccBoard = New MccDaq.MccBoard(0)l
Dim I As Short
Private Sub Score_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ScoreValue As Decimal = 0
'ULStat = DaqBoard.DIn(PortNum, DataValue)
Dim GameScore As String = "C:\SavedGame.txt"
If System.IO.File.Exists(GameScore) = True Then
Dim objReader As New System.IO.StreamReader(GameScore)
ValueBox.Text = objReader.ReadToEnd
objReader.Close()
If lblBitVal(I).Text = "0" Then
ScoreValue += 1
Else
ScoreValue -= 0.5
End If
TextBox1.Text = ScoreValue
End Sub
It won't register lblBitVal in this form. It says "Object reference not set to an instance of an object." Also, this only adds 1 if there is a file opened. I need to it read the file and at least add a point for each time stamp that is recorded.
Let me know if you guys know how I can go about this since my game is almost complete :). THANKS AGAIN!
i've created a dance mat game similar to Dance Dance Revolution. It has 4 arrows and when no step is taken it's a binary value 1111. When the up arrow is stepped on the binary value is 1110. I'm having problems with my scoring guide. I'm using streamwriter and streamreader to record the time stamp and the binary value of each step taken and once the game is done I have the file display the timestamps and the binary values. For right now I just want it to add one point for whenever it registers a step taken. This is the code I have that records the timestamp and the binary value. lblBitValue is the value that changes from a 1 to 0 binary.
Private Sub tmrReadInputs_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrReadInputs.Tick
Dim I As Short
Dim ULStat As MccDaq.ErrorInfo
Dim DataValue As UInt16
tmrReadInputs.Stop()
' read FirstPortA digital input and display
' Parameters:
' PortNum :the input port
' DataValue :the value read from the port
ULStat = DaqBoard.DIn(PortNum, DataValue)
If ULStat.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop
' display the value collected from the port
lblPortRead.Text = DataValue.ToString("0")
' parse DataValue into bit values to indicate on/off status
For I = 0 To 3
If (Convert.ToInt32(DataValue) And CInt((2 ^ I))) <> 0 Then
lblBitVal(I).Text = "1" 'NO STEP TAKEN
Else
lblBitVal(I).Text = "0" 'STEP TAKEN
TextBox1.Text = Trim(Format(Now, "hh:mm:ss tt "))
Dim GameFile As New System.IO.StreamWriter("C:\SavedGame.txt", OnGoingGame)
GameFile.WriteLine(TextBox1.Text & DataValue)
GameFile.Close()
OnGoingGame = True
End If
Next I
tmrReadInputs.Start()
End Sub
For the Scoring form I have the following:
Public Class Score
Public lblBitVal As System.Windows.Forms.Label()
Const PortNum As MccDaq.DigitalPortType = MccDaq.DigitalPortType.FirstPortA ' set port to use
Private DaqBoard As MccDaq.MccBoard = New MccDaq.MccBoard(0)l
Dim I As Short
Private Sub Score_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ScoreValue As Decimal = 0
'ULStat = DaqBoard.DIn(PortNum, DataValue)
Dim GameScore As String = "C:\SavedGame.txt"
If System.IO.File.Exists(GameScore) = True Then
Dim objReader As New System.IO.StreamReader(GameScore)
ValueBox.Text = objReader.ReadToEnd
objReader.Close()
If lblBitVal(I).Text = "0" Then
ScoreValue += 1
Else
ScoreValue -= 0.5
End If
TextBox1.Text = ScoreValue
End Sub
It won't register lblBitVal in this form. It says "Object reference not set to an instance of an object." Also, this only adds 1 if there is a file opened. I need to it read the file and at least add a point for each time stamp that is recorded.
Let me know if you guys know how I can go about this since my game is almost complete :). THANKS AGAIN!