Server Help

Bot Questions - error C2440

minor59er - Thu Feb 15, 2007 9:14 am
Post subject: error C2440
error C2440: '=' : cannot convert from 'char' to 'char [20]'

been working at this all night anyone got any solutions for me? much appreciated.

this is in command.cpp
Code: Show/Hide
         if (c->check("reg"))
         {
            p->name = playerName[regNum];
            regNum++;
            sendPrivate(p, "You have been registerd to play this session.");
         }

myke - Thu Feb 15, 2007 9:47 am
Post subject:
what i don't understand is why are you trying to change p->name, from what i can see it looks like you're trying to make an array'd list of people who reg for a game.


if that is what you're trying to do, try changing

Code: Show/Hide
p->name = playerName[regNum];


to

Code: Show/Hide
playerName[regNum] = p->name;

Witchie NL - Thu Feb 15, 2007 10:30 am
Post subject:
indeed, p->name is an char[20] array type which cant be initialized in such a way.
however you can change the value of playerName[#] (# is regNum in this case).

so what myke sais is an option.
Cyan~Fire - Thu Feb 15, 2007 10:36 am
Post subject:
Which is why you should actually learn C++ before trying to make bots.
minor59er - Thu Feb 15, 2007 9:16 pm
Post subject:
Ah crap... i didn't even notice it... was so tired last night... ahahahaha, im so stupid for that. Thanks for pointing that out for me icon_smile.gif

And btw i haven't done a course but i spent a few weeks reading "C++ - How To Program, 5th Edition (2005)" so i do have some knowledge.. just didn't realize that i was trying to put an array into a pointer..
Animate Dreams - Thu Feb 15, 2007 9:27 pm
Post subject:
Cyan~Fire wrote:
Which is why you should actually learn C++ before trying to make bots.


I spent my time reading books and tutorials instead of actually trying to program something, and I regret that, because I still don't know how to program. But I learned 90% of what I know through attempts, not the books I read.
Witchie NL - Fri Feb 16, 2007 7:57 am
Post subject:
i learned everything i know now by looking at other sources.
I did read a book from the liberary when i started coding but i stoped at chapter 4 of 17, which just where some basics (!, ==, ++, --, -=, +=, %, /, {} etc... not even array and pointers which where chapter 5).
so i had to learn practicly everything from scratch (was a bitch tho).
Cyan~Fire - Fri Feb 16, 2007 10:27 am
Post subject:
Well, I'm sorry reading didn't work out too well for you guys, but I definitely got my basic C++ knowledge from the tutorial I link all over the place here. Obviously coding is what makes you really understand the stuff, but if you don't get the basics (pointers, etc.) and then come running to a forum when you get a compile error, you're going about it the wrong way.
minor59er - Fri Feb 16, 2007 8:22 pm
Post subject:
Ok, since my code that ive tried hasn't worked, and i looked up usign a reinterpret_cast, and my attempt is this..

Code: Show/Hide
         if (c->check("reg"))
         {
            playerName[regNum] = reinterpret_cast <char> (p->name);
            sendPrivate(p, &playerName[regNum]);
            sendPrivate(p, "You have been registerd to play this session.");
            regNum++;
         }


But when i try to call a name from the array it comes out in
"ÅÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"

Any ideas on this?
Cyan~Fire - Fri Feb 16, 2007 8:52 pm
Post subject:
Read a stupid tutorial. You're copying a char, not a char array (string).

Character sequences
minor59er - Fri Feb 16, 2007 10:14 pm
Post subject:
you don't have to be so rude.
Bak - Fri Feb 16, 2007 10:39 pm
Post subject:
try this:
Code: Show/Hide
strcpy(playerName, p->name);

Cyan~Fire - Sun Feb 18, 2007 1:05 am
Post subject:
I already suggested it two times, but I'm sorry for being rude.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group