Loading...
Logo
Processing Forum

Tab Communication

in Programming Questions  •  5 months ago  
Hi there,

I am wondering if there is a way to send variable data from one tab to another in a sketch?

Any help would be greatly appreciated :)

Thanks.


Replies(7)

Re: Tab Communication

5 months ago
of course
tab is just a way to organise visually your sketch.
you just  can't split method into several tabs.

ahh right okay. Would this work? This is the kind of think I am talking about. Thanks again for your help.


// TAB1:

int x;


void setup()
{
  size(700,700);
}

void draw() {
  
  background(0);
  
  ellipse(x,100,100,100);
  

}


//TAB2:

class helloTab
{
  

void setup() {
  x = mouseX;
}
}

Re: Tab Communication

5 months ago

It'll work

internally it's always one tab only
For some reason i can't get the previous example to work. The sketch loads but the ellipse doesn't follow the mouse.

Any ideas??

Re: Tab Communication

5 months ago

there is a class but you don't get an object  from it

Try this (no class here,.but 2 tabs)

Copy code
  1. // TAB1:
  2. int x;
  3. void setup()
  4. {
  5.   size(700,700);
  6. }
  7. void draw() {
  8.   
  9.   background(0);
  10.   checkMouse();
  11.   ellipse(x,100,100,100);
  12.   
  13. }
  14. //TAB2:
  15. void checkMouse()
  16. {
  17.   
  18.   x = mouseX;
  19. }

Thank you very much :)

Worked perfectly! 

Re: Tab Communication

5 months ago
You're treating each tab like it's a different thing.
It's not.
Tabs are only used to help you partition your code in a meaningful way.
All your code - in any tab - is all at the same level and in the same place.

Example:

// TAB 1:

int x;

// TAB 2:

void setup(){
  size(400,400);
  fill(255,0,0);
}

// TAB 3:

void draw(){
  background(0);
  ellipse( mouseX, mouseY, 20, 20);
  x = 23;
}