Null links

BlitzMax Forums/BlitzMax Beginners Area/Null links

Ant(Posted 2006) [#1]
Hi, confused why this code isnt working.

I'm defining the following:


Now to my mind, the code shouldnt enter the WHILE loop unless link and link.nextLink() arent null (ie the objects they reference exist in the list). But my code enters the While loop, gets get to nextObject=Object(link.nextlink().value()) and complains about an unhandled exception.

I guess link.nextlink() is the problem, but I cant see the issue?

Thanks!


tonyg(Posted 2006) [#2]
This doesn't enter the loop...
list:TList=CreateList()
link:TLink=list.firstLink()
While link And link.nextLink()
  Print "In here"
 currentObject=Object(link.value())
 nextObject=Object(link.nextlink().value())

Wend

Link and link.nextlink are both null as nothing has been added to the list. However, specifying link as TLink might have helped.
This is a simpler example...
list:TList=CreateList()
link:TLink=list.firstLink()
If link
  Print "link exists"
Else
  Print "link is null"
EndIf

<edit> Just in case...
list:TList=CreateList()
Type test
End Type
link:TLink=list.firstLink()
While link And link.nextLink()
  Print "In here"
 currentObject=Object(link.value())
 nextObject=Object(link.nextlink().value())
Wend
Print "outta here"
For x = 1 To 2
	my:test=New test
	ListAddLast list,my
Next
link:TLink=list.firstLink()
While link And link.nextLink()
  Print "In here"
 currentObject=Object(link.value())
 nextObject=Object(link.nextlink().value())
Wend
Print "outta here"



Eric(Posted 2006) [#3]
removed


Ant(Posted 2006) [#4]
here is the full code (I had actually added objects and made link type TLink - sorry should have posted this before)


I'm getting an unhandled exception error where I assign nextball=TBall(link.nextlink().value()) - not on the first iteration, usually the 4th time.

I dont understand how this could happen when the code should only enter the while loop if link AND link.nextLink() arent NULL?


tonyg(Posted 2006) [#5]
Hmmm, that's not the full code either but never mind.
In addition, you haven't got a simple 'link and link.nextlink()' condition.
Anyway, is the following really doing what your comments say?
		While link And link.nextlink() And prevPathLink Or nextPathLink

What if you change it to...
while link and link.nextlink and (prevpathlink or nextpathlink)



Ant(Posted 2006) [#6]
Adding the parenthesis seems to solve that particular problem - what was it evaluating without them?


tonyg(Posted 2006) [#7]
I believe it was evaluating...
while (link and link.nextlink and prevpathlink) or nextpathlink



Ant(Posted 2006) [#8]
Great. Thanks for the much needed assistance!