Uh? Assigning values instead of checking equality

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

gburgess(Posted 2008) [#1]
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?


tonyg(Posted 2008) [#2]
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



gburgess(Posted 2008) [#3]
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.


gburgess(Posted 2008) [#4]
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 :(


tonyg(Posted 2008) [#5]
... a method of which type? TPage or another object?
Having said that this works as expected for me

and so does this :

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


gburgess(Posted 2008) [#6]
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.


tonyg(Posted 2008) [#7]
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.


grable(Posted 2008) [#8]
Or there could be variable misspelling, or even scoping issues.
Try switching to SuperStrict mode and see what crops up.