Reputation: 7
I'm trying to make a game using vb,so i made this class:
Imports Microsoft.VisualBasic.PowerPacks
Module EntityI
Public entities As List(Of Entity)
Public Function getEntity(ByVal uuid As Guid) As Entity
For i = 0 To entities.Count - 1
If entities.Item(i).getUUID = uuid Then
Return entities.Item(i)
End If
Next
Return Nothing
End Function
End Module
Public Class Entity
Private uuid As Guid
Private location As Location
Private shape As OvalShape
Public Sub New()
uuid = System.Guid.NewGuid
Dim canvas As New PowerPacks.ShapeContainer
canvas.Parent = Game
shape = New OvalShape With {.Parent = canvas}
shape.SetBounds(50, 50, 50, 50)
save()
End Sub
Public Function getUUID() As Guid
Return uuid
End Function
Public Function getLocation() As Location
Return location
End Function
Public Sub teleport(ByVal location As Location)
Me.location = location
End Sub
Private Sub save()
entities.add(Me)
End Sub
End Class
So this gives an error at entities.add(Me) (NullRefernceException). Is it something with the list or something else? Help please.
Upvotes: 0
Views: 71
Reputation: 177
You are new list. You are only declaring the variable as a list. Change Public entities As List(Of Entity)
to Public entities As New List(Of Entity)
Upvotes: 0