Hi, I'm wondering if someone can takea look at this snippet of code. Its basically a search which is based upon a object passed to it. The search will basically keep searching out from its passed object until it doesnt find any other objects of the same colour and then it returns the list its created. The actual search works well, but the problem I am having is that this line:
returnedGem.time = priority
Rather than take the value of 'priority' which is incremented each time the main loop is executed, each gem in the returned list always has a priority value of 3 - which is the number of times the 'returnedGem.Time = priority ' line is executed when this code is executed. I just dont understand it - the list of objects that it creates is perfectly fine and contains all the objects it should, so why does the priority variable for all the objects = 3
Thanks
returnedGem.time = priority
Rather than take the value of 'priority' which is incremented each time the main loop is executed, each gem in the returned list always has a priority value of 3 - which is the number of times the 'returnedGem.Time = priority ' line is executed when this code is executed. I just dont understand it - the list of objects that it creates is perfectly fine and contains all the objects it should, so why does the priority variable for all the objects = 3
Thanks
Method FloodFillSearch:TList( sourceGem:TGem ) ' A local list is used to keep track of the ones we still have to search Local listToSearch:TList = CreateList() ' A local list that is returned Local listToReturn:TList = CreateList() Local link:TLink Local Gem:TGem = sourceGem Local returnedGem:TGem Local priority:Int = 0 ' Add the gem to the list listToSearch.addLast ( gem ) link = listToSearch.FirstLink() While listToSearch.count() > 0 priority:+1 gem = TGem( link.value() ) returnedGem= ColoursearchUp ( gem, 1 ) If returnedGem And ( Not listToReturn.contains ( returnedGem ) ) returnedGem.time = priority listToSearch.AddLast ( returnedGem ) EndIf returnedGem= ColoursearchDown ( gem, 1 ) If returnedGem And ( Not listToReturn.contains ( returnedGem ) ) returnedGem.time = priority listToSearch.AddLast ( returnedGem ) EndIf returnedGem= ColoursearchLeft ( gem, 1 ) If returnedGem And ( Not listToReturn.contains ( returnedGem ) ) returnedGem.time = priority listToSearch.AddLast ( returnedGem ) EndIf returnedGem= ColoursearchRight ( gem, 1 ) If returnedGem And ( Not listToReturn.contains ( returnedGem ) ) returnedGem.time = priority listToSearch.AddLast ( returnedGem ) EndIf listToReturn.addlast( Gem ) RemoveLink ( Link ) link = listToSearch.FirstLink() Wend For Local AGEM:TGEM = EachIn listtoreturn DebugLog "Gem Time: "+gem.priority Next Return listToReturn EndMethod Method ColourSearchUp:TGem( sGem:TGem, CellStep:Int ) 'Validate that search isnt outwith boarm If sGem.YCell-CellStep < 0 Return Null EndIf If myboard.board [ sGem.xCell , sGem.YCell-CellStep ].colour = sGem.colour Return myboard.board [ sGem.xCell , sGem.YCell-CellStep ] Else Return Null EndIf EndMethod Method ColourSearchDown:TGem( sGem:TGem, CellStep:Int ) 'Validate that search isnt outwith board If sGem.YCell+CellStep > ( ROWS-1 ) Return Null EndIf If myboard.board [ sGem.xCell , sGem.YCell+CellStep ].colour = sGem.colour Return myboard.board [ sGem.xCell , sGem.YCell+CellStep ] Else Return Null EndIf EndMethod Method ColourSearchLeft:TGem( sGem:TGem, CellStep:Int ) 'Validate that search isnt outwith board If sGem.XCell-CellStep < 0 Return Null EndIf If myboard.board [ sGem.xCell-CellStep , sGem.YCell ].colour = sGem.colour Local tempGem:TGem = myboard.board [ sGem.xCell-CellStep , sGem.YCell ] Return myboard.board [ sGem.xCell-CellStep , sGem.YCell ] Else Return Null EndIf EndMethod Method ColourSearchRight:TGem( sGem:TGem, CellStep:Int) 'Validate that search isnt outwith board If sGem.XCell+CellStep > ( COLUMNS-1 ) Return Null EndIf If myboard.board [ sGem.xCell+CellStep , sGem.YCell ].colour = sGem.colour Return myboard.board [ sGem.xCell+CellStep , sGem.YCell ] Else Return Null EndIf EndMethod