well i'm finished world editor great community, thing need know how can tell read file code process specific letters. when hit enter on keyboard write coordinates of vector3f text file, vector3f posistion of active gameobject. processtext method can read text file , process coordinates can read ony type of format:
public void processtext() { string file_name = "c:/users/server/desktop/texttext.txt"; try { processcoords file = new processcoords(file_name); string[] arylines = file.openfile(); int i; (i = 0; < arylines.length; i++) { system.out.println(arylines[i]); if(arylines[i].startswith("makegrass:")) { string arguments = arylines[i].substring(arylines[i].indexof(":")+1, arylines[i].length()); string[] argarray = arguments.split(","); this.makegrass(double.parsedouble(argarray[0]), double.parsedouble(argarray[1]), double.parsedouble(argarray[2])); } } } catch(ioexception e) { system.out.println(e.getmessage()); } } in above example processtext method can process coordinates if written this:
makegrass:x,y,z //for example makegrass:5,1,9 but when press enter , write coordinates me engine gives i'm getting different format:
makegrass:(x y z) //for example makegrass:(3 1 4) now need know how have rewrite code in processtext method accounts other format has brackets @ beginning , end , spaces sepearta x y , y z instead of commas.
i don't knwo else find answer question i'd apreciate , explanation how works.
thanks lot in advance!
you want accept many formats possible?
instead of splitting try match, safer , doesn't need pre- or post-processing of input or received substrings:
pattern pattern = pattern.compile("([0-9]+)"); // outside of method long[] argarray = new long[3]; matcher matcher = pattern.matcher(arguments); int = 0; while (matcher.find() && < 3) { argarray[i++] = long.parselong(matcher.group(1)); } // there mistake if < 3, otherwise have 3 numbers in argarray if want split, maybe try this: split("[^0-9]+")
to match makegrass:(x y z)
pattern pattern = pattern.compile("^makegrass:\\(([0-9]+) ([0-9]+) ([0-9]+)\\)$"); like can directly match line , have 3 numbers in groups 1 - 3 (as string) after calling find once, if (matcher.find()) decide if it's valid makegrass line , if can processed in if.
Comments
Post a Comment