Uh? Assigning values instead of checking equality

BlitzMax Forums/BlitzMax Programming/Uh? Assigning values instead of checking equality

I'm having a really confusing problem with BlitzMax. I'm basically writing a simple crawler for individual sites, and I've got a Type, TPage, where every newly detected page is placed. Here's the code for adding a new page object:
	Function Create:TPage(nsite$,nport%,naddress$,nawaitingCrawl%=1)
		AddTextAreaText(output_TextArea:TGadget,Chr$(10)+"Checking: "+naddress$+" ")
;CHECK IF PAGE ALREADY EXISTS
		For checkPage:TPage=EachIn PageList
			If checkPage.address$=naddress$ And checkPage.site$=nsite$ And checkPage.port%=nport%
				AddTextAreaText(output_TextArea:TGadget,Chr$(10)+"Exists: "+naddress$+" "+checkPage.awaitingCrawl%)
				Return checkPage
			EndIf
		Next
;OTHERWISE, CREATE IT
		AddTextAreaText(output_TextArea:TGadget,Chr$(10)+"New: "+naddress$)
		Local p:TPage=New TPage
		p.address$=naddress$
		p.content$=""
		p.awaitingCrawl%=nawaitingCrawl%
		p.site$=nsite$
		p.port%=nport%
		ListAddLast(PageList,p)
		Return p
	End Function

As you can see, it first checks existing pages to see if the new one has actually already been detected and added to the list. If so, it just returns the existing one.

At least, that's what supposed to happen. The problem is, after much debug checking, this line:
If checkPage.address$=naddress$ And checkPage.site$=nsite$ And checkPage.port%=nport%


I feel like I'm missing something really obvious, but I just don't see it. What seems to be happening is this:
1) The program adds the first page. This works fine.
2) The program detects several links in this page and proceeds to add more.
3) At this stage, as the Create function is called for each new page.
4) Each time the create function is called for these new pages, the above line evaluates to true. Each = operator is treated like an assignment operator, and checkPage is given the values, rather than being compared to them.
5) End result: every time the Create function is called after the initial call, the one page in the list is assigned the new values, instead of a new page being created, so I can never have more than one, constantly changing page in the list.

BMax doesn't seem to support the == operator for checking equality, so...

What am I doing wrong?

You don't say what the problem is.
Anyway, this works for me and, as far as I can see, its doing the same thing
Type TPAGE
	Global pagelist:TList=CreateList()

	Field SITE:String
	Field PORT:Int
	Field ADDRESS:String
	Field AWAITINGCRAWL:Int


	Function Create:TPAGE(nsite$,nport%,naddress$,nawaitingCrawl%=1)
'CHECK If PAGE ALREADY EXISTS
		For checkPage:TPage=EachIn PageList
			If checkPage.address$=naddress$ And checkPage.site$=nsite$ And checkPage.port%=nport%
				Print "Found it"
				Return CHECKPAGE
			EndIf
		Next
' OTHERWISE, Create IT
		Local p:TPage=New TPage
		Print "NEW one created"
		p.address$=naddress$
		p.awaitingCrawl%=nawaitingCrawl%
		p.site$=nsite$
		p.port%=nport%
		ListAddLast(PageList,p)
		Return P
	End Function
End Type

Local PAGE1:TPAGE=tpage.Create("one",80,"HELLO")
Local PAGE2:TPAGE=tpage.Create("two",80,"WORLD")

Local PAGE3:TPAGE=tpage.Create("one",80,"HELLO")


Sorry, I guess I wasn't very explicit, but it's here where the problem is:
4) Each time the create function is called for these new pages, the above line evaluates to true. Each = operator is treated like an assignment operator, and checkPage is given the values, rather than being compared to them.

So after the first page is made, new pages are no longer created, the one existing one gets the new values assigned in that 'IF' statement, rather than them being compared.

That said, the code you posted does indeed work fine for me. I'm so stumped.

Okay, I think I found the problem. This seems like it could be a bug: when I was calling the create function, it was from inside a method. I changed it to a function, and it seems to be working. The code isn't quite as tidy, though :(

... a method of which type? TPage or another object?
Having said that this works as expected for me
Type TPAGE
	Global pagelist:TList=CreateList()

	Field SITE:String
	Field PORT:Int
	Field ADDRESS:String
	Field AWAITINGCRAWL:Int
	
	
	Function Create:TPAGE(nsite$,nport%,naddress$,nawaitingCrawl%=1)
'CHECK If PAGE ALREADY EXISTS
		For checkPage:TPage=EachIn PageList
			If checkPage.address$=naddress$ And checkPage.site$=nsite$ And checkPage.port%=nport%
				Print "Found it"
				Return CHECKPAGE
			EndIf
		Next
' OTHERWISE, Create IT
		Local p:TPage=New TPage
		Print "NEW one created"
		p.address$=naddress$
		p.awaitingCrawl%=nawaitingCrawl%
		p.site$=nsite$
		p.port%=nport%
		ListAddLast(PageList,p)
		Return P
	End Function
End Type

Type ttest

	Function Createpagefunction()

		Local PAGE1:TPAGE=tpage.Create("one",80,"HELLO")
		Local PAGE2:TPAGE=tpage.Create("two",80,"WORLD")
		Local PAGE3:TPAGE=tpage.Create("one",80,"HELLO")
	End Function
	
	Method createpagemethod()
		Local PAGE1:TPAGE=tpage.Create("one",80,"HELLO")
		Local PAGE2:TPAGE=tpage.Create("two",80,"WORLD")
		Local PAGE3:TPAGE=tpage.Create("one",80,"HELLO")
	End Method	
	
End Type

Print "Function call"
ttest.createpagefunction()
ClearList(tpage.pagelist)
Local mytest:ttest=New ttest
Print "Method call"
mytest.createpagemethod()


and so does this :
Type TPAGE
	Global pagelist:TList=CreateList()

	Field SITE:String
	Field PORT:Int
	Field ADDRESS:String
	Field AWAITINGCRAWL:Int
	
	Method callcreatemethod()
		Local PAGE1:TPAGE=tpage.Create("one",80,"HELLO")
		Local PAGE2:TPAGE=tpage.Create("two",80,"WORLD")
		Local PAGE3:TPAGE=tpage.Create("one",80,"HELLO")
	End Method

    Function callcreatefunction()	
		Local PAGE1:TPAGE=tpage.Create("one",80,"HELLO")
		Local PAGE2:TPAGE=tpage.Create("two",80,"WORLD")
		Local PAGE3:TPAGE=tpage.Create("one",80,"HELLO")
	End Function
	
	Function Create:TPAGE(nsite$,nport%,naddress$,nawaitingCrawl%=1)
'CHECK If PAGE ALREADY EXISTS
		For checkPage:TPage=EachIn PageList
			If checkPage.address$=naddress$ And checkPage.site$=nsite$ And checkPage.port%=nport%
				Print "Found it"
				Return CHECKPAGE
			EndIf
		Next
' OTHERWISE, Create IT
		Local p:TPage=New TPage
		Print "NEW one created"
		p.address$=naddress$
		p.awaitingCrawl%=nawaitingCrawl%
		p.site$=nsite$
		p.port%=nport%
		ListAddLast(PageList,p)
		Return P
	End Function
End Type


Print "Function call"
tpage.callcreatefunction()
ClearList(tpage.pagelist)
Local mytest:tpage=New tpage
Print "Method call"
mytest.callcreatemethod()


You might want to provide similar code showing the suspected bug.

It's a method of TPage. I'll look into it. I still can't shake the feeling I've just forgotten something, especially since your code seems to be working okay.

The only thing I can think is your sending the data from the instance (e.g. self) which MUST exist as you're running it from a method.

Or there could be variable misspelling, or even scoping issues.
Try switching to SuperStrict mode and see what crops up.