Java use a piece of code from a text file -


i trying figure out. world editor want program read text file , use content code material. i've made decent file reader i've got problem. in console getting right output, file has 1 line says:

this.makegrass(new vector3f(0, 1, 2)); 

this part of code tells program render specific object scene, in case it's grass model. instead of printing information console with

system.out.println(arylines[i]); 

i want able use information stored on .txt file can add rendering code. entire method prints lines on text file console is:

     public void textoutput()      {         string file_name = "c:/text.txt";          try         {             storecoords file = new storecoords(file_name);             string[] arylines = file.openfile();              int i;             (i = 0; < arylines.length; i++)             {                 system.out.println(arylines[i]);             // !! how use information part of code ??             }         } catch(ioexception e)         {             system.out.println(e.getmessage());         }      } 

i hope understand want: content of text file piece of code want use further instead of having print console, i'm sure possible wouldn' know how.

thanks help!

as java compiled language, you'd have recompile @ runtime , not sure possible. if you, i'd hardcode in own commands. want call function called makegrass, hardcode in. maybe in text file can have this:

    makegrass:0,1,2 

then have right after println:

    if(arylines[i].startswith("makegrass:")) {             string arguments = arylines[i].substring(arylines[i].indexof(":")+1, arylines[i].length());             argarray = arguments.split(",");             this.makegrass(new vector3f(double.parsedouble(argarray[0]), double.parsedouble(argarray[1]), double.parsedouble(argarray[2])));     } 

i'm going leave answer this, assuming experienced programmer. if wrong feel free ask , explain you. can explain how modify add different commands if want.

also, rather unsafe because if input in wrong format crash app. if plan on letting users edit file, can show how add on safeties.

hope helped, joseph meadows


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -