Compile Error: Identifier '...' not found
BlitzMax Forums/BlitzMax Beginners Area/Compile Error: Identifier '...' not found
| ||
I think I am crazy or stupid. I cannot compile because I receive and error message. I tried to make simple example. Here it is my "sample" code.. In the same BMX file I have: Type TLogicScene Field sceneID:Int Field sceneOpen:Int EndType Type TGamelogic Field logicScene:TLogicScene Function isSceneOpen(tmpSceneID:Int) Print logicScene.sceneID Return 1 End Function Method StartNewGameLogic() logicScene = New TLogicScene logicScene.sceneID = 1 logicScene.sceneOpen = 1 End Method EndType Well, whne compiling I receive a message: Compile Error: Identifier 'sceneID' not found The error is throw by the Function not by the method As I said earlier my original example was more complex, but I tried to minimize it. P.S. Also If I make a Method instead of a Function, the code is compiled. Last edited 2012 |
| ||
If I make a Method instead of a Function, the code is compiled. That's because, in the context of this short example, the code should be a method. Remember, the difference (in fact, only difference) between a method and a function is that a function has "static scope" (which is why you'll occasionally see them referred to as "static methods"). In other words, they can only "see" a type's scoped globals and constants and are more or less the same as functions declared elsewhere, because they don't implicitly "belong" to an object. Since fields are properties of an object, not shared across the whole type, they can only be accessed by a method, which also belongs to the object (has "object scope") and can operate on its components. So, either: -- make isSceneOpen a method (since the TLogicScene is an object property) -- make isSceneOpen accept a TLogicScene parameter to operate on (makes some sense, since it doesn't really operate on any aspect of the TGameLogic) -- move isSceneOpen to be a method of TLogicScene, since really it only operates on that anyway But however you do it, it has to be able to see a TLogicScene object before it can operate on it, and functions don't get to implicitly "see" fields: only methods can do that. Last edited 2012 |
| ||
I see. Also I found this discussion here: http://blitzbasic.com/Community/posts.php?topic=42919 Now I think I understand. Thank you for the quick answer. |