zloop1982 / bwapi

Automatically exported from code.google.com/p/bwapi
0 stars 0 forks source link

DEFECT: getOrderTarget()/getTarget() clears Unit*->getType().getName() field #499

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Call getOrderTarget()/getTarget() on a Unit*
2. Retrieve the value of Unit*->getType().getName() (which is null)

What is the expected output? What do you see instead?
Expected: Name of Unit*, Actual: NULL

What version of the product are you using? On what operating system?
R4160

E.G:
Unit* target = (*p)->getOrderTarget();
std::string test = target->getType()->getName();
Broodwar->printf("Type: %s", test);

Original issue reported on code.google.com by mdsumne...@gmail.com on 10 Nov 2013 at 11:29

GoogleCodeExporter commented 9 years ago
This is the result of printf accepting character arrays only, and you are 
passing in an object of type std::string.

If you use Broodwar->printf("Type: %s", test.c_str()); then it should work.

For convenience you may use target->getType().c_str(); as a shortcut instead of 
target->getType().getName().c_str();

In BWAPI 4 (r4350+) this syntax is
Broodwar << "Type: " << target->getType() << std::endl;

Original comment by AHeinerm on 11 Nov 2013 at 12:50