Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Stuck at the first code line of the terrarium...
 

Stuck at the first code line of the terrarium...

I made the code according to the tutorial, however when I load I get the error message that animal.myanimal cannot be found in the assembly.

Can someone please check what I am doing wrong since I would like to be able to play the terrarium game but now I can't even program 1 actionTongue Tied.

edit at some code it said:


'Instructions: Cut and paste into a class file in a VB class library

' project. The project must have its default namespace cleared in

' the project properties.


How do I do this?


code:

<Assembly: OrganismClass("Animal.MyAnimal")>

<Assembly: AuthorInformation("Your Name", x@x.xx)>

< _

Carnivore(False), _

MatureSize(28), _

AnimalSkin(AnimalSkinFamily.Beetle), _

MarkingColor(KnownColor.Red), _

MaximumEnergyPoints(20), _

EatingSpeedPointsAttribute(0), _

AttackDamagePointsAttribute(12), _

DefendDamagePointsAttribute(12), _

MaximumSpeedPointsAttribute(16), _

CamouflagePointsAttribute(10), _

EyesightPointsAttribute(20) _

> _

Public Class MyAnimal : Inherits Animal

' The current plant we're going after

Dim targetPlant As PlantState = Nothing

' Fired after all other events are fired during a turn

Sub MyAnimal_Idle(ByVal sender As Object, ByVal e As IdleEventArgs)

Try

' Reproduce as often as possible

If (CanReproduce) Then

BeginReproduction(Nothing)

End If

' If we can eat and we have a target plant, eat

If (CanEat) Then

WriteTrace("Hungry.")

If Not (IsEating) Then

WriteTrace("Not eating: Have target plant?")

If Not (targetPlant Is Nothing) Then

WriteTrace("Yes, Have target plant already.")

If (WithinEatingRange(targetPlant)) Then

WriteTrace("Within Range, Start eating.")

BeginEating(targetPlant)

If (IsMoving) Then

WriteTrace("Stop while eating.")

StopMoving()

End If

Else

If Not (IsMoving) Then

WriteTrace("Move to Target Plant")

BeginMoving(New MovementVector(targetPlant.Position, 2))

End If

End If

Else

WriteTrace("Don't have target plant.")

If Not (ScanForTargetPlant()) Then

If Not (IsMoving) Then

WriteTrace("No plant found, so pick a random point and move there")

Dim RandomX As Integer = OrganismRandom.Next(0, WorldWidth - 1)

Dim RandomY As Integer = OrganismRandom.Next(0, WorldHeight - 1)

BeginMoving(New MovementVector(New Point(RandomX, RandomY), 2))

Else

WriteTrace("Moving and Looking...")

End If

End If

End If

Else

WriteTrace("Eating.")

If (IsMoving) Then

WriteTrace("Stop moving while eating.")

StopMoving()

End If

End If

Else

WriteTrace("Full: do nothing.")

If (IsMoving) Then

StopMoving()

End If

End If

Catch exc As Exception

WriteTrace(exc.ToString())

End Try

End Sub

' Looks for target plants, and starts moving towards

' the first one it finds

Function ScanForTargetPlant() As Boolean

Try

Dim foundCreatures As System.Collections.ArrayList = Scan()

If (foundCreatures.Count > 0) Then

Dim orgState As OrganismState

' Always move after closest plant

' or defend closest creature if there is one

For Each orgState In foundCreatures

If (TypeOf orgState Is PlantState) Then

targetPlant = CType(orgState, PlantState)

BeginMoving(New MovementVector(orgState.Position, 2))

Return True

End If

Next

End If

Catch exc As Exception

WriteTrace(exc.ToString())

End Try

Return False

End Function

' First event fired on an organism each turn

Sub MyAnimal_Load(ByVal sender As Object, ByVal e As LoadEventArgs)

Try

If Not (targetPlant Is Nothing) Then

' See if our target plant still exists

' (it may have died)

' LookFor returns null if it isn't found

targetPlant = CType(LookFor(targetPlant), PlantState)

If (targetPlant Is Nothing) Then

' WriteTrace is the best way to debug your creatures.

WriteTrace("Target plant disappeared.")

End If

End If

Catch exc As Exception

WriteTrace(exc.ToString())

End Try

End Sub

Protected Overloads Overrides Sub Initialize()

AddHandler Idle, AddressOf MyAnimal_Idle

AddHandler Load, AddressOf MyAnimal_Load

' TODO: Add Initialization logic here

End Sub

Public Overloads Overrides Sub SerializeAnimal(ByVal m As MemoryStream)

' TODO: Add Serialization logic here

End Sub

Public Overloads Overrides Sub DeserializeAnimal(ByVal m As MemoryStream)

' TODO: Add Deserialization logic here

End Sub

End Class

<Assembly: OrganismClass("Animal.MyAnimal")> a

<Assembly: AuthorInformation("Your Name", "x@xx.com")>

< _

Carnivore(False), _

MatureSize(28), _

AnimalSkin(AnimalSkinFamily.Beetle), _

MarkingColor(KnownColor.Red), _

MaximumEnergyPoints(20), _

EatingSpeedPointsAttribute(0), _

AttackDamagePointsAttribute(12), _

DefendDamagePointsAttribute(12), _

MaximumSpeedPointsAttribute(16), _

CamouflagePointsAttribute(10), _

EyesightPointsAttribute(20) _

> _

Public Class MyAnimal : Inherits Animal

' The current plant we're going after

Dim targetPlant As PlantState = Nothing

' Fired after all other events are fired during a turn

Sub MyAnimal_Idle(ByVal sender As Object, ByVal e As IdleEventArgs)

Try

' Reproduce as often as possible

If (CanReproduce) Then

BeginReproduction(Nothing)

End If

' If we can eat and we have a target plant, eat

If (CanEat) Then

WriteTrace("Hungry.")

If Not (IsEating) Then

WriteTrace("Not eating: Have target plant?")

If Not (targetPlant Is Nothing) Then

WriteTrace("Yes, Have target plant already.")

If (WithinEatingRange(targetPlant)) Then

WriteTrace("Within Range, Start eating.")

BeginEating(targetPlant)

If (IsMoving) Then

WriteTrace("Stop while eating.")

StopMoving()

End If

Else

If Not (IsMoving) Then

WriteTrace("Move to Target Plant")

BeginMoving(New MovementVector(targetPlant.Position, 2))

End If

End If

Else

WriteTrace("Don't have target plant.")

If Not (ScanForTargetPlant()) Then

If Not (IsMoving) Then

WriteTrace("No plant found, so pick a random point and move there")

Dim RandomX As Integer = OrganismRandom.Next(0, WorldWidth - 1)

Dim RandomY As Integer = OrganismRandom.Next(0, WorldHeight - 1)

BeginMoving(New MovementVector(New Point(RandomX, RandomY), 2))

Else

WriteTrace("Moving and Looking...")

End If

End If

End If

Else

WriteTrace("Eating.")

If (IsMoving) Then

WriteTrace("Stop moving while eating.")

StopMoving()

End If

End If

Else

WriteTrace("Full: do nothing.")

If (IsMoving) Then

StopMoving()

End If

End If

Catch exc As Exception

WriteTrace(exc.ToString())

End Try

End Sub

' Looks for target plants, and starts moving towards

' the first one it finds

Function ScanForTargetPlant() As Boolean

Try

Dim foundCreatures As System.Collections.ArrayList = Scan()

If (foundCreatures.Count > 0) Then

Dim orgState As OrganismState

' Always move after closest plant

' or defend closest creature if there is one

For Each orgState In foundCreatures

If (TypeOf orgState Is PlantState) Then

targetPlant = CType(orgState, PlantState)

BeginMoving(New MovementVector(orgState.Position, 2))

Return True

End If

Next

End If

Catch exc As Exception

WriteTrace(exc.ToString())

End Try

Return False

End Function

' First event fired on an organism each turn

Sub MyAnimal_Load(ByVal sender As Object, ByVal e As LoadEventArgs)

Try

If Not (targetPlant Is Nothing) Then

' See if our target plant still exists

' (it may have died)

' LookFor returns null if it isn't found

targetPlant = CType(LookFor(targetPlant), PlantState)

If (targetPlant Is Nothing) Then

' WriteTrace is the best way to debug your creatures.

WriteTrace("Target plant disappeared.")

End If

End If

Catch exc As Exception

WriteTrace(exc.ToString())

End Try

End Sub

Protected Overloads Overrides Sub Initialize()

AddHandler Idle, AddressOf MyAnimal_Idle

AddHandler Load, AddressOf MyAnimal_Load

' TODO: Add Initialization logic here

End Sub

Public Overloads Overrides Sub SerializeAnimal(ByVal m As MemoryStream)

' TODO: Add Serialization logic here

End Sub

Public Overloads Overrides Sub DeserializeAnimal(ByVal m As MemoryStream)

' TODO: Add Deserialization logic here

End Sub

End Class

SDK1985  Saturday, June 10, 2006 2:25 PM
I assume you're using VS 2003.  If not, what are you using?  If so, there should be a setting in the project's properties called "Root Namespace", or something like that.  By default, it is set to the name of your project.  When you find it, delete it so that there is no root namespace.  Alternatively, you can change the 

<Assembly: OrganismClass("Animal.MyAnimal")>

line with

<Assembly: OrganismClass("[ProjectName].MyAnimal")>

where [ProjectName] is the name of your project.

dkocur2  Monday, June 19, 2006 3:06 PM

First, did you clear the default namespace, per the comments at the top of the file?

The project must have its default namespace cleared in the project properties

Second, it doesn't look like "MyAnimal" is in the "Animal" namespace, it looks like it's in the root namespace. Therefore, the line should state...

<Assembly: OrganismClass("MyAnimal")>

Hope this helps!

dkocur2  Friday, June 16, 2006 2:31 PM

I have no idea what the author meant by that since I cannot find a property named default or namespace...

I know tried this:

The class hould be ok now (VBAnimal.Creature then I name the Class file in the project Creature)

However still errors, still don't know what is meant by that clearing part.

SDK1985  Saturday, June 17, 2006 4:42 PM
I assume you're using VS 2003.  If not, what are you using?  If so, there should be a setting in the project's properties called "Root Namespace", or something like that.  By default, it is set to the name of your project.  When you find it, delete it so that there is no root namespace.  Alternatively, you can change the 

<Assembly: OrganismClass("Animal.MyAnimal")>

line with

<Assembly: OrganismClass("[ProjectName].MyAnimal")>

where [ProjectName] is the name of your project.

dkocur2  Monday, June 19, 2006 3:06 PM

You can use google to search for other answers

Custom Search

More Threads

• Window messages
• How to Set Quick Start Tutorial
• Well, this is it
• Research on Terrarium...Please Help me ASAP!
• Is it possible to use the PhotoListView outside of this application?
• email encode easy to thwart?
• form data refresh
• Can I print to a RichTextBox using a StreamWriter?
• WS-Security
• ASP.Net Client for TaskVision?