Duplicate identifier question

BlitzMax Forums/BlitzMax Beginners Area/Duplicate identifier question

PowerPC603(Posted 2005) [#1]
Hi, I'm creating some custom types for my space game.

If I use this function in a module (inside a type):
Function FindCommodity:TCommodityType(CommName$)
	For Local a:TCommodityType = EachIn TCommodityType.AComm
		If a.IsWare() Then
			Local b:TWareType = TWareType(a)
			If b.Name$ = CommName$ Then Return a
		EndIf

		If a.IsWeapon() Then
			Local b:TWeaponType = TWeaponType(a)
			If b.Name$ = CommName$ Then Return a
		EndIf

		If a.IsMissile() Then
			Local b:TMissileType = TMissileType(a)
			If b.Name$ = CommName$ Then Return a
		EndIf

		If a.IsUpgrade() Then
			Local b:TUpgradeType = TUpgradeType(a)
			If b.Name$ = CommName$ Then Return a
		EndIf
	Next
End Function

It works fine.
It even compiles without errors.

But when I copy the same function into an empty bmx file and try to run it (even without extra code to call the function), using the button "Build and Run", I get an error that "b" is a duplicate identifier.
And the IDE points to line 9 ("Local b:TWeaponType = TWeaponType(a)") inside the IF-block "If a.IsWeapon()".

Does Local work differently if used in a module?


skidracer(Posted 2005) [#2]
It works differenty if you are in Strict mode. In non strict compiling there is no local scope only function scope which I assume is what is causing your error.


PowerPC603(Posted 2005) [#3]
Thanks for the reply and this was the cause.

I just created a new, empty bmx file, copied the function into it and I've put Strict at the top of the file and now it compiles without errors.
I commented the Strict and the error appeared.

Thanks.


Dreamora(Posted 2005) [#4]
Why does something like that work differently in strict than in none strict?

Isn't the purpose of strict to force declaration and disable some stuff?
Then why is it changing half of the language behavior?