5 Replies - 5382 Views - Last Post: 26 July 2011 - 02:19 PM Rate Topic: -----

#1 JizzaDaMan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 139
  • Joined: 23-May 11

Game Of Life

Posted 26 July 2011 - 02:23 AM

In the game, I'm using labels and the backcolor property to change their living status.
I have an array of the labels. However, when changing their life status using a for loop, i've come across a problem where previous elements in the array effect the next ones before the end of the generation.
I found somewhere that recommende I use a different array, However, im not too sure how.

        For x = 0 To 400
            Boxes(x).Neighbours = GetNeighbours(x)
            If Boxes(x).Neighbours = 0 Or Boxes(x).Neighbours = 1 Then
                Boxes(x).Alive = False
            ElseIf Boxes(x).Neighbours = 2 Or Boxes(x).Neighbours = 3 Then
                Boxes(x).Alive = True
            Else
                Boxes(x).Alive = False
            End If
        Next

This post has been edited by JizzaDaMan: 26 July 2011 - 02:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Game Of Life

#2 Shiggsy  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 65
  • Joined: 14-July 11

Re: Game Of Life

Posted 26 July 2011 - 03:14 AM

This isn't exactly what you asked for, but why do you have extra code?

For X = 0 to 400
 Boxes(x).Neighbours = GetNeighbours(x)
 If Boxes(X).Neighbours > 1 OR < 4 Then
  Boxes(x).Alive = True
 Else
  Boxes(x).Alive = False
 End If
Next X


Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,083
  • Joined: 02-July 08

Re: Game Of Life

Posted 26 July 2011 - 08:47 AM

The expression must be evaluated on each side of the boolean checks.

If Boxes(X).Neighbours > 1 OR < 4 Then
needs to be
If Boxes(X).Neighbours > 1 AndAlso Boxes(X).Neighbours < 4 Then

This post has been edited by hawkvalley1: 26 July 2011 - 08:50 AM

Was This Post Helpful? 0
  • +
  • -

#4 Shiggsy  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 65
  • Joined: 14-July 11

Re: Game Of Life

Posted 26 July 2011 - 09:35 AM

I didn't want to stunt his development by giving him perfect code :/
Mistakes help you learn.
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,083
  • Joined: 02-July 08

Re: Game Of Life

Posted 26 July 2011 - 12:39 PM

Huh! I don't agree. If your posting code to help you should always teach the best practice you know.
Was This Post Helpful? 3
  • +
  • -

#6 JizzaDaMan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 139
  • Joined: 23-May 11

Re: Game Of Life

Posted 26 July 2011 - 02:18 PM

hey guys, i didn't ask for an argument, and I would kinda like the right code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1