Page 2 of 2

Posted: Wed May 19, 2010 10:35 pm
by Th3xpl0iT
SendChatMessage is being a burden to use when dealing with int's, float's, etc. What's the AND type of thing I should use when including a number with a string? Example:

Code: Select all

m_game->SendChatMessage("Longitude: " & longitude, CHATCHANNEL_PUBLIC);

Posted: Wed May 19, 2010 11:05 pm
by Montyphy
Since you seem new to C++ programming you may want to do a tutorial first (in particular, typecasting, strings, and iostreams) or use a language which is less type restrictive, such as Lua. ;)

Posted: Thu May 20, 2010 10:42 pm
by Th3xpl0iT

Code: Select all

#include <string>
#include <iostream>
using namespace std;

int main(void) {
string r1 = "No I'm not that new to C++";
string r2 = "just working with a Defcon Bot API lol";

cout << r1 << " " << r2 << endl;

}


Posted: Thu May 20, 2010 11:03 pm
by Th3xpl0iT
The biggest problem I have (I got my bot to place a radar down, so I just gotta get the rest of the x,y's to place stuff in) is to have a single instance of an action. I tried:

Code: Select all

int i = 0;

if (i==0) {
m_game->PlaceStructure(3, -72, 40.75);
i++;
}


But it keeps doing the same thing, even when 'i' is clearly not eq to 0.

Posted: Fri May 21, 2010 7:33 am
by Montyphy
Th3xpl0iT wrote:

Code: Select all

string r1 = "No I'm not that new to C++";
string r2 = "just working with a Defcon Bot API lol";


If that were the case you wouldn't need to ask how to concatenate a string and float. ;)

Th3xpl0iT wrote:The biggest problem I have (I got my bot to place a radar down, so I just gotta get the rest of the x,y's to place stuff in) is to have a single instance of an action. I tried:

Code: Select all

int i = 0;

if (i==0) {
m_game->PlaceStructure(3, -72, 40.75);
i++;
}


But it keeps doing the same thing, even when 'i' is clearly not eq to 0.


What do you mean it keeps doing the same thing? What are you expecting it to do? Are you expecting it to place different locations? All that code snippet does is place a structure in a hard coded location (without first testing if it's a valid location). The i variable can essentially be ignored since it will be initialized to 0, making the if statement true, and nothing is done with it after it's incremented.

EDIT:

Rather than using 3 to refer to a structure type you should be using the defined constant, RadarStation.

Posted: Fri May 21, 2010 4:16 pm
by xander
Th3xpl0iT wrote:SendChatMessage is being a burden to use when dealing with int's, float's, etc. What's the AND type of thing I should use when including a number with a string? Example:

Code: Select all

m_game->SendChatMessage("Longitude: " & longitude, CHATCHANNEL_PUBLIC);


Something like this might be what you need to do:

Code: Select all

char message[32];

sprintf(message, "%s%f", "Longitude: ", longitude);
m_game->SendChatMessage(message, CHATCHANNEL_PUBLIC);

However, I don't know the Defcon API at all, so there may be some problems with variable types in the above. That being said, Montyphy is correct. You really do need to spend some time learning the language.

xander

Posted: Fri May 21, 2010 11:19 pm
by Th3xpl0iT
Montyphy wrote:
Th3xpl0iT wrote:

Code: Select all

string r1 = "No I'm not that new to C++";
string r2 = "just working with a Defcon Bot API lol";


If that were the case you wouldn't need to ask how to concatenate a string and float. ;)

Th3xpl0iT wrote:The biggest problem I have (I got my bot to place a radar down, so I just gotta get the rest of the x,y's to place stuff in) is to have a single instance of an action. I tried:

Code: Select all

int i = 0;

if (i==0) {
m_game->PlaceStructure(3, -72, 40.75);
i++;
}


But it keeps doing the same thing, even when 'i' is clearly not eq to 0.


What do you mean it keeps doing the same thing? What are you expecting it to do? Are you expecting it to place different locations? All that code snippet does is place a structure in a hard coded location (without first testing if it's a valid location). The i variable can essentially be ignored since it will be initialized to 0, making the if statement true, and nothing is done with it after it's incremented.

EDIT:

Rather than using 3 to refer to a structure type you should be using the defined constant, RadarStation.


When I say "It does the same thing", I mean exactly that - It constantly would send "HELLO WORLD" if the code was:

Code: Select all

int i = 0;
if (i==0) {
m_game->SendChatMessage("HELLO WORLD", CHATCHANNEL_PUBLIC);
i++;
}


This would become handy because I want my bot to say to the Alliance what to do according to the Defcon level (I know how to do it, except the repeat problem).

And I suppose my most important question/problem (along with ordering an Airbase to send fighters to an x,y location >_<): Fleets. How the hell can I put a fleet into the water? It's been driving me nuts - The Constants .pdf file said that '8' was Battleship, so I would do:

Code: Select all

m_game->PlaceFleet(test_x, test_y, 8, 8, 8, 8, 8, 8);


And it wouldn't appear.

EDIT: Learned how to put boats in the water lmao. Now to learn how to order Airbases, as well as switching my Silos to Nuke mode and having them launch against the enemy.

Posted: Sat May 22, 2010 2:08 am
by Montyphy
Th3xpl0iT wrote:When I say "It does the same thing", I mean exactly that - It constantly would send "HELLO WORLD" if the code was:

Code: Select all

int i = 0;
if (i==0) {
m_game->SendChatMessage("HELLO WORLD", CHATCHANNEL_PUBLIC);
i++;
}


This would become handy because I want my bot to say to the Alliance what to do according to the Defcon level (I know how to do it, except the repeat problem).


So, you have your single instance of code which will repeat any time it's call for the reason I described yet you don't want it doing it the same thing? By "It does the same thing" do you actually mean it keeps executing the PlaceStructure code when you only want it to be called once? So basically, you're trying to ask how to have a piece of code only execute once? By "single instance" I thought you were talking about how many times a piece of code appeared in your project, i.e. refactor a piece of code to loop over the available units to place them.

If it is the case of you wanting to execute code only once then you can either check the value of the tick, or use global flags that get set to true or false when you want to trigger certain events, or a slight variant of the global boolean would be a global integer which gives a finer degree than Defcon level. An example of the first method can be found here

Th3xpl0iT wrote:And I suppose my most important question/problem (along with ordering an Airbase to send fighters to an x,y location >_<): Fleets. How the hell can I put a fleet into the water? It's been driving me nuts - The Constants .pdf file said that '8' was Battleship, so I would do:

Code: Select all

m_game->PlaceFleet(test_x, test_y, 8, 8, 8, 8, 8, 8);


And it wouldn't appear.

EDIT: Learned how to put boats in the water lmao. Now to learn how to order Airbases, as well as switching my Silos to Nuke mode and having them launch against the enemy.


As I previously said, don't use the numeric value for selecting units. Use the name defined in enums.h. So rather than 8, use TypeBattleShip in the same way you're suppose to use CHATCHANNEL_PUBLIC rather than 100

Posted: Sat May 22, 2010 7:17 pm
by Th3xpl0iT
Thank you very much, you don't know how much of a help you're being.

My bot can improve a little better if I can figure out how to:

  • Tell my Silos to attack the enemy
  • Tell my Airbases to send Fighters/Bombers to specific coordinates
  • Tell my Fleets specifically where to move/attack, as well as telling them what state they should be in.


But I got a lot covered in the past few days, so thank you for helping me this far!