Game Development Community

Cant get console method to set variable right

by Bryan Stroebel · in Torque Game Engine · 05/17/2006 (2:25 pm) · 3 replies

Ok. I know this may be simple but I can't seem to figure it out.

I have a public variable in a class that i set to NULL in the constructor for the class.
const char* myvar;

I have a console method that just sets the value of that variable to the string I pass in as argv[2]
ConsoleMethod(myclass,mymethod,void,3,3,"cm(myvar)")
{
	object->myvar = argv[2];
}

However, when I print out the value of myvar after the console method is run, it comes out as a "y".
when I change the consolemethod to the following it works:
ConsoleMethod(myclass,mymethod,void,3,3,"cm(myvar)")
{
	object->myvar = "hello world";
}

Is there somekind of conversion that I need to do to get the passed argv[2] into myvar properly? I've tried casts and conversions and nothing works.

#1
05/17/2006 (2:32 pm)
Try

object->myvar = StringTable->insert(argv[2]);

Ian
#2
05/17/2006 (2:33 pm)
Also, if you want to pass in something that isn't a char, use the functions:

dAtob(argv[2]); // boolean
dAtoi(argv[2]); // int
dAtof(argv[2]); // float

Ian
#3
05/17/2006 (5:56 pm)
Thanks ian. This worked.