We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › strange tab behaviour [fixed] why is this
Page Index Toggle Pages: 1
strange tab behaviour [fixed] why is this? (Read 367 times)
strange tab behaviour [fixed] why is this?
Jun 7th, 2009, 3:34am
 
Ok, so I was having this weird issue, which is what the following rambling is all about, however I fixed my problem, but it brings up a new question, plus I thought I'd post this since someone else might have a problem with this. So if you like, you can read the following post, to get some context, and my question is after.



So I'm trying to split up my code into manageable pieces, because I'm trying to do a tetris implementation of oo-game-design by Britt L. Hannah, which is a bit of a mindf**k

sorry for not giving a link, first post restrictions and all. All you need to know is that action, and entity, are base classes.

anyways, I make tabs for action and entity objects. Now, actions take entities in their constructor, and entities take actions in a few of their methods. I didn't expect ordering to be an issue, because I have some old code in front of me of the form
Code:

tab 1: "A_PIXEL"

class pixel{
 …

  pixel(…, charge Q){
   …
  }
 

  }


Tab 2: C_CHARGE
class charge{
 …
 
 charge(…){
   …
 }
}


which runs fine.

however this
Code:

tab 1:"b_Actions"

String ROTATE="Rotate";
String DESCEND="Descend";


class Action extends NonRenderableObject{
 //run, jump, shoot, accelerate, explode, etc.
 //Action objects are invoked by Entity objects, and can affect other Entity objects.
 
 Action(){
 }
 
 void doAction(){
 }
 
}


class Rotate{
 Rotate(Entity entity){
   
 }
 
}


tab2: "c_entity"

class Entity extends NonRenderableObject{
//This represents a game token. It can be anything that exists in game
 Entity(){
 
 }
 
 //Assigns a State to Entity
 void assignState(State state, String stateName){
 }
 
 //Assigns an Action to Entity
 void assignAction(Action action, String actionName){
 }
 
 //Asks for State if it exists; returns null if no state exists
 State hasState(String stateName){
   State S=new State();
   return S;
 }
 
 //Activates the action
 void activateAction(String actionName){
 }
 
 //Deactivates the action
 void deactivateAction(String actionName){
 }
 
 //do each active action
 void doActions(){
 }

}




does not. I get the error
'Cannot find a class or type named "Entity"'

I've labeled the tabs that way to control the order of their appearance. The reason for this is; if I remove "Entity entity" from the rotate constructor, then the code runs fine, but then if I change the order of the tabs by changing the alphabetical ordering of the tab names, the code does not run, and I get the error
'Cannot find a class or type named "Action"'

This suggests to me that it can't find the class because it is defined in the tab following it. But if that were the case, my other code should not run.



Anyways, I realized the problem is that my code didn't have a setup() function in it. But my question now is, why does not having setup in your code do this?


Re: strange tab behaviour [fixed] why is this?
Reply #1 - Jun 7th, 2009, 12:15pm
 
I think I can answer the last question, more or less.

You can type a bunch of lines and just run it. Processing will wrap it automatically with a setup() routine, itself wrapped with a class having also a main() method.

But if you add a function to the bunch, you will get an error: Processing doesn't know how to break the code (should these declarations be global, ie. class level, or go to setup()?) so it puts everything in setup and you end with an error since in Java you cannot put a function inside another.

If you declare two classes without giving a setup(), they will go in setup(). Yes, a function can have classes inside...
But apparently, they cannot reference each other. Not sure why, in practice we never use such construct (except for anonymous classes, of course).

Now, if you declare an explicit setup(), everything falls in place: setup() is at the same level as the two classes, the latter can reference each other.
Page Index Toggle Pages: 1