c# - How to open a textfile in XNA/monogame(beginner here)? -


okay, working in xna , want open textfile should open in textfile. here code:

 if (keyboard.getstate().iskeydown(keys.g) == true)                  {                     var filetoopen = "name.txt";                     var process = new process();                     process.startinfo = new processstartinfo()                     {                         useshellexecute = true,                         filename = filetoopen                     };                      process.start();                     process.waitforexit();                 } 

however error occurs , cant find textfile open. did in normal consol application , added new item textfile project , worked fine in console application, in xna not seem work @ all.

also im not educated in file directory things , need quick fix. text files placed in area:
file location image

i hope of somehelp im trying give information possible. note streamwriting textfiles in directory location shown in image link works fine , give name of file shown below:

if (player.getrec.intersects(map.sharkrec))                 {                     using (streamwriter writer = new streamwriter("currentscore.txt"))                     {                         writer.write(time);                      }                     player.position = new vector2(64,100);                       mcurrentscreen = screenstate.leaderboard;                 } 

however didt seem work when want open textfile in notepad , allow typing done in textfile in notepad. reason why want open text file typing user entering there name , dont have knowledge or time xna textbox input creation seems complicated tutorials have seen, why want open textfile in notepad editing. furthermore going used on other people's computers if directorys have used need directory work on other computers own, note directory entering seems confuse me.

hope have given enough information , hope can beginner out here :)

for work, code should this:

      using(streamwriter ...)     {         show textbox user can see he's typing         each keypress add letter         exit on esc button (for example)         delete char on backspace         etc...     }  

now, personaly don't recommend type of code. open file, have , close it. code below how programmed textbox game. hope helps (you more little tutoial better approach problem instead answer exact problem put yourself).

      namespace acircalipse.menuclasses     {         public class textbox:menuitem         {             private string origintitle;         public string text         {                 {         return title.replace(origintitle, "").replace(menu.separator, "");         }         }         public int index, max;          public      textbox     (string title, string text = "", int maxcharacters = 14)         {         origintitle = title;         index = 0;         max = maxcharacters;         settext(text);         }         public void     settext     (string text)         {         if (text.length > max) text = text.substring(0, max);         title = origintitle + menu.separator + text;         }          public void     changeindex     (int howmuch)         {         index += howmuch;            changecar(index);         }         public void     addchar     (int index = 0)         {         settext(text + menu.wheel(index));         }         public void     changecar       (int index)         {         if(text.length > 0)         settext(text.substring(0, text.length - 1) + menu.wheel(index));         }         public void     deletechar      ()         {         if (text.length > 0)         settext(text.substring(0, text.length - 1));         }         }     } 

where menu.wheel(int index) array of available character user type in

      public static char wheel(int index)     {         string charwheel = " abcdefghijklmnopqrstuvwxyz0123456789";         int max = charwheel.length;         while (index > max) index -= max;         while (index ("less than" sign here) 0) index += max;         return charwheel[index];     }  

where menu.separator string ": ".

code pretty self explanatory.
now, when using class, you'll have have 1 bool see if user has activated textbox, , if has, add text on keypress. if textbox inactive, continue normal update

what have understand textbox simple string witch updated when textbox active, , showed when not active.
using simple , on point definition of textbox, can create own class work way want to.

if answer helped resolve problem, please mark solution.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -