Quantcast
Channel: Questions in topic: "log"
Viewing all articles
Browse latest Browse all 235

Cannot get boolean to log correctly

$
0
0
Hey there, I'm having a problem with a log script I'm writing. When displaying the coordinates of the player it works perfectly fine but now I also want to include a boolean to track if and when the player opens their map, Somehow however the changes do not make their way into the log. This is the script I wrote: public class Log : MonoBehaviour { public TextWriter fs; public GameObject playerobject; public bool PositionLogging = true; bool is_logging = false; float deltaTime = 1f; // every 1s float timeToLog; bool mapShowing; void Start () { playerobject = GameObject.Find ("RigidBodyFPSController"); if (is_logging) return; if (!Directory.Exists(@".\logs")) Directory.CreateDirectory(@".\logs"); var nameOfLogFile = (2+"")+ "_log.csv"; this.fs = new StreamWriter(Path.Combine("./logs",nameOfLogFile), true){AutoFlush = true}; this.fs.WriteLine("#Time is| " + System.DateTime.Now.ToLongTimeString() +" "+ System.DateTime.Now.ToLongDateString() ); this.fs.WriteLine("#logged object is | " + this.name); this.fs.WriteLine("#Format is | time (sec since program start)|x|y|z| map showing"); is_logging = true; bool mapShowing = false; } void Update() { if (!is_logging || Time.time < timeToLog || !PositionLogging) return; timeToLog = Time.time + deltaTime; if (Input.GetKeyDown ("m") || Input.GetButtonDown ("X-Key")) mapShowing = !mapShowing; fs.Write(String.Format("{0:0.0000000}|", Time.time)); //foreach(ILoggable l in this.loggables) if(l.Logg()) fs.Write(l.ToLogg()); fs.Write(mapShowing); fs.Write(Environment.NewLine); } private string LoggTransform (GameObject playerobject) { return String.Format("{0:0.0000}|{1:0.0000}|{2:0.0000}|{3:0}", playerobject.transform.position.x, playerobject.transform.position.y, playerobject.transform.position.z, mapShowing); } } Here just as an example a log, during which I pressed the "m"/map-key at least 10 times... ![alt text][1] Do you have any idea how I could fix this? Thanks, Lukas [1]: /storage/temp/66366-unbenannt.jpg

Viewing all articles
Browse latest Browse all 235

Trending Articles