0

Using Write Log for Debugging

I want to learn how to correctly use write log to help with my debugging.  The following is a program that I have some debug statements in and then some code I thought would print the write log out in the chat window.  Can someone tell me what I am missing?

 

using System;
using System.Collections.Generic;
using System.Text;
using Sansar;
using Sansar.Script;
using Sansar.Simulation;

// This example shows how to use coroutines
public class RotateObjectScipt : SceneObjectScript
{
// The RigidBodyComponent is the interface for dynamic object interactions.

private RigidBodyComponent RigidBody = null;
private Quaternion Orientation;
private float zstart;

public override void Init()
{
// If the object had its components set in the editor they should now have the member initialized
// [Editor support for Component types is not yet implemented]
// The component can also be found dynamically
Log.Write("Mike: In Init");

ScenePrivate.Chat.Subscribe(0, null, GetChatCommand, true);

if (RigidBody == null)
{
if(!ObjectPrivate.TryGetFirstComponent(out RigidBody))
{
// This example will only work on a dynamic object with a rigidbody. Bail if there isn't one.
return;
}
}

//Custom Code. Init is the Constructor for all Objects
StartCoroutine(Spinner);
}

private void Spinner()
{
while (true)
{
Log.Write("Mike: In Spinner");
RotateObject();
Timer.Create(TimeSpan.FromMilliseconds(10), RotateObject);
}
}

private void RotateObject()
{
//Rotate Object
Log.Write("Mike: In RotateObject");
Orientation = Quaternion.FromEulerAngles(new Vector(0.0f, 0.0f, zstart, 0.0f));
RigidBody.SetOrientation(Orientation);
zstart = zstart + 5.0f;
}

public void GetChatCommand(int Channel, string Source, SessionId SourceId, ScriptId SourceScriptId, string Message)
{
if (Message == "/listlog")
{
StartCoroutine(ListLogMessages);
}
}

private void ListLogMessages()
{
foreach (var Agent in ScenePrivate.GetAgents())
{
StringBuilder list = new StringBuilder();
foreach (var message in Log.Messages)
{
list.AppendLine(message.Text);
}
list.AppendLine("End of messages");
Agent.SendChat(list.ToString());
}
}

}

7 comments

Please sign in to leave a comment.