Autor Tema: father... (i hate it) and a new project  (Leído 1502 veces)

Zip

  • Full Member
  • ***
  • Mensajes: 158
  • Karma: 11
    • OPENCONSOLE.IT
father... (i hate it) and a new project
« en: Febrero 24, 2011, 09:52:48 pm »
HI  ;)
i've a new project on my mind...
thats the link,

you have tryed to explane me how work father,
i dont understand

u can see in the folder basic example
the file that i try to learn,
and in other folder my project u can find
the version workly, and the version using father dont work  :o

i hope an angel can finnally explain me

http://www.zshare.net/download/870391513aeda169/

josebita

  • Administrator
  • *****
  • Mensajes: 4039
  • Karma: 257
    • BennuGD Mobile Worklog
Re: father... (i hate it) and a new project
« Respuesta #1 en: Febrero 25, 2011, 12:44:23 pm »
Father is a variable that contains the identificator for the process that created you.
You can access that process' local variables like this:
[code language="bennu"]father.x
father.y
father.graph
father.angle...[/code]
Please be aware that in case the process that created you has died, the code above will crash, therefore you must always check father is still alive before trying to access its local variables:
[code language="bennu"]if(exists(father))
x = father.x; y = father.y;
end[/code]

http://wiki.bennugd.org/index.php?title=Father

Zip

  • Full Member
  • ***
  • Mensajes: 158
  • Karma: 11
    • OPENCONSOLE.IT
Re: father... (i hate it) and a new project
« Respuesta #2 en: Febrero 28, 2011, 10:14:44 am »
i need to use another process to make father condition?
like
Código: [Seleccionar]
father()
father.x=x
father.x=x+1
end

proces()
press left x=x-1
end

Drumpi

  • Hero Member
  • *****
  • Mensajes: 6340
  • Karma: 162
  • Odio el periodo "entre proyectos"
    • La web de Drumpi
Re: father... (i hate it) and a new project
« Respuesta #3 en: Febrero 28, 2011, 01:21:09 pm »
No, FATHER is a predefined local variable (look for "local variable" in wiki or tutorial), you don't need/can do another process with father name.

Let me explain (again):
Think a program is a tree. Your main process is the root of all, every process main create is a branch, for example, main creates p1, p2 and p3. If p1 creates more process, they will be p1 branches. Suposse that p1 has 2 branches, called p11 and p12.
Every branch is a SON of the process who creates him, so p1, p2 and p3 are main's sons. It means main is father of p1, p2 and p3. And p11 and p12 are p1's sons, so p1 is p11 and p12 father.

So, p1, p2 and p3 has a variable named FATHER with main ID number, and p11 and p12 has a variable called FATHER with p1 ID number.
Wath can you do with ID number? you can modify it's process local variables, like X, Y, GRAPH, ALPHA (in wiki there is a list of predefined local variables) and all you declared at the begining.

So, if a son wants to change the father position it needs his ID, saved on local variable FATHER, and new value. p11 will modify X position of p1 like this:

father.x=x+1;

If p1 wants to modify main process GRAPH, it can do this way:

father.graph=23;

I hope you had understand it now.

EDIT:

I readed your code, and pp0_0_0_3father.prg has no sense:
[code language="bennu"]global
int gfx;
begin
     set_mode(320,240,16);
    gfx=load_fpg("gfx.fpg");
     put_screen(gfx,2);
   
    player();
  loop
     if(key(_ESC))
       break;
     end
    frame;
  end
  let_me_alone();
end

process player()
begin
 write_var(0,210,5,0,angle);
 graph=1;
 x=40;
 y=20;
 
 loop

  if (key(_right))
  advance(8);
  end
  if (key(_up))
  angle=angle+10000;
  end
  if (key(_down))
  angle=angle-10000;
  end
  if (father.y<-11)
  father.y=father.y+12;
  end
 
  frame;
 end
end[/code]

Player don't need to change main process position (lines 43-45) because main process has no graph, you need to change player graph, so no sense to use father.

If you are using TUTOR04 as a reference, the "corrige_coordenadas" process is trying to change "nave" and "asteroide" position (but not at the same time, nave creates a corrige_coordenada process who will modify its own variables, and asteroide creates ANOTHER corrige_coordenada process for its own variables). It's not the same case as yours.
« última modificación: Febrero 28, 2011, 01:32:01 pm por Drumpi »
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

Zip

  • Full Member
  • ***
  • Mensajes: 158
  • Karma: 11
    • OPENCONSOLE.IT
Re: father... (i hate it) and a new project
« Respuesta #4 en: Marzo 01, 2011, 04:23:11 pm »
first of all, thanx =)
second.. i dont wanna change graph of player, just set limit like i do in the other example pp0_0_0_3.prg, but using father
Código: [Seleccionar]

global
int gfx;
begin
     set_mode(320,240,16);
gfx=load_fpg("gfx.fpg");
     put_screen(gfx,2);

player();
  loop
     if(key(_ESC))
       break;
     end
    frame;
  end
  let_me_alone();
end

process player()
begin
 write_var(0,210,5,0,angle);
 graph=1;
 x=40;
 y=20;
 
 loop

  if (key(_right))
  advance(8);
  end
  if (key(_up))
  angle=angle+10000;
  end
  if (key(_down))
  angle=angle-10000;
  end
[b]  if (y<-11)
  y=y+12;
  end[/b]
 
  frame;
 end
end