Java, change boolean from another class -
this question different because it's creating 3d world editor.. @ moment want updated positions of models work..
so i've worked way rather simple problem. in order update scene want have boolean if specific input given , change false true once input given.. problem though input method has in class , don't know how can affect boolean there.. here's code:
public class enginesetup extends game { public boolean dostuff = true; public void init() { creationtool updatecoords = new creationtool(this); while(dostuff == true) { updatecoords.environment(); dostuff = false; } } }
this happens when engine starts. it's going run environment method in creationtool class once, because after first execution dostuff changes false.
public class creationtool extends gamecomponent { public void input(float delta) { if(input.getkeyup(getcoords)) // change boolean value in enginesetup true } }
in creationtool class have input method , getcoords variable enter key.
so idea once hit enter key boolean in enginesetup class set true , environment method being executed once again , boolean changed false again.
how can change boolean value within creationtool class decribed above?
thanks lot help!
edit: i've gotten answers none of them worked..
public class enginesetup extends game { private static enginesetup instance; public boolean dostuff = true; public void init() { instance = this; creationtool updatecoords = new creationtool(this); while(dostuff == true) { system.out.println("work"); dostuff = false; } } public class creationtool extends gamecomponent { public void input(float delta) { if(input.getkeyup(getcoords)) { enginesetup.getinstance().dostuff=true; } } }
it works first time around when program starts when hit enter nothing happens.
public class enginesetup extends game { public static boolean dostuff = true; public void init() { creationtool updatecoords = new creationtool(this); while(dostuff == true) { system.out.println("work"); dostuff = false; } } public class creationtool extends gamecomponent { public void input(float delta) { if(input.getkeyup(getcoords)) enginesetup.dostuff = true; } }
also didn't work, first time around when program start everything's fine when hit enter: nothing..
how fix..?
okay, i've restructured code little , got booleans work way wanted. moved boolean enginesetup class creationtool class, input , change booelans there:
public class engineinput extends game { public void init() { if(creationtool.dostuff == true) { system.out.println("updatevegetation "+creationtool.dostuff); this.updatevegetation(); // method updates coordinates } else if(creationtool.dostuff == false) system.out.println("updatevegetation "+creationtool.dostuff); } }
and in creationtool class can affect boolean:
public class creationtool extends gamecomponent { public static boolean dostuff = true; engineinput updatevegetation = new engineinput(); public void input(float delta) { if(dostuff == true) { if(input.getkeyup(getcoords)) { system.out.println(dostuff); dostuff = false; updatevegetation.updatevegetation(); } } else if(dostuff == false) { if(input.getkeyup(getcoords)) { system.out.println(dostuff); dostuff = true; updatevegetation.updatevegetation(); } } } }
thanks help! coordinates being read text file once hit enter key, updated positions still rendered after restarting program, riddle need solve.
Comments
Post a Comment