0
votes

I'm working with Unity(+Vuforia), and I'm having some problems trying to print some variables that I want to identify the vuMark Augmented Reality Object (this a Vuforia thing) with, but I can't seem to get it to work.

My code is below, where I want the vuMarkID to be compared to "Table". In the DebugLog, however, my second statement (Debug.Log("vuMarkCompareToTable...")) returns 1. Even though the first statement (Debug.Log("ID = {0}"...)) returns "Table". I have tried trimming the vuMarkID string object, and also tried converting it directly, as you see below.

The other strange thing is nothing will print after "Table" in the debug log, for the first statement. I've tried concatenating using something like vuMarkID+"END", and the statement just cuts off at "Table". I've even tried printing using "ID = {0}{0}", and only the first "Table" prints. Even if the vuMarkID object changes (for instance, to Stool), it still does not print anything after the initial vuMarkID object.

How can I get the Debug.Log to recognize text after "Table" and have the CompareTo function return 0 when the arguments are (seemingly) the same?

Edit: I tried Debug.Log(string.Format("ID = " + vuMarkID + "DONE")); as well (I'm trying to see if there's something after the text), but that also cuts off immediately after the vuMarkID. I tried replacing for newline, just in case it was there, but it didn't have an effect.

//Gets the id of a VuMark Object 
string vuMarkID = GetVuMarkId(vuMarkObj).ToString();
if (vuMarkID.CompareTo("Table ") == 0)
{
    Debug.Log("Table found from tracking!");
}
else
{
    string logdebug = vuMarkID;
    object[] args = new object[] { (vuMarkID), vuMarkID.CompareTo("Table") };
    Debug.Log(string.Format("ID = {0}", logdebug));
    Debug.Log("vuMarkCompareToTable = " + (vuMarkID.Trim().CompareTo("Table")));

}
1
You cant use Debug.Log like a Console.WriteLine, replace (string.Format("ID = {0}", logdebug) with (string.Format("ID = {0} " + logdebug).Arman Papikyan
For some reason, it doesn't like that. I get Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.A4Treok
Than congratulations. Your problem of 'not showing the whole text' was fixed, now it seems your vuMarkID is out of range (is less than 0), you have to fix that to use its value.Arman Papikyan
@ArmanPapikyan the exception is because of what you suggested. As it is wrong syntax of String.Format().Umair M
Oh that was an argument for string.Format, ok my bad. I thought oyu were passing it as an argument for Debug.Log.Arman Papikyan

1 Answers

0
votes
if (vuMarkID.CompareTo("Table ") == 0)

Note the " "(space) after Table.

If vuMarkID is "Table", it would go to else statement as it doesn't match.

You need to remove space:

if (vuMarkID.Trim().CompareTo("Table") == 0)

And to print object if its something else:

do this:

string vuMarkID = GetVuMarkId(vuMarkObj).ToString();
Debug.Log(vuMarkID); // this will always tell you id. No matter what it is.

if (vuMarkID.CompareTo("Table") == 0)
{
    Debug.Log("Table found from tracking!");
    // do table related stuff.
}

Hope this helps