qboolean == integer?

So I'm getting a number of a qboolean, which works fine:
g_Engine.Con_Printf("%d\n", GetPlayerUniqueID); // Print out my number / ID.

Then I get the number of it, now if I get a number shouldn't it be possible to do if ( GetPlayerUniqueID == number ) ? The reason is that it doesn't work.

This is my error: operand types are incompatible ("qboolean (*)(int iPlayer, char *playerID)" and "int")

This is the structure of the qboolean function:
qboolean (*GetPlayerUniqueID)(int iPlayer, char playerID[16]);

I know booleans cannot return more than 0 and 1, but I don't really know what's going on if I can get the number of this function but I cannot check if it has a certain number. This is for/from a game.
Here

GetPlayerUniqueID == number

in the left side GetPlayerUniqueID is a function that is converted to a pointer to function. You can not compare a pointer to function with an integer. And the compiler says you about such restriction. read the compiler messages. They are displayed specially for you.

I think you should use the following form

GetPlayerUniqueID( SomeInt, SomePointerToChar) == number

provided that return type of the function is an integer type.
Thanks for your reply.

So I tried what you said, now I debugged that line and I got a ID of 0:


char * playerID[16] // Global, above all functions


// All under a looping function
if ( g_Engine.GetPlayerUniqueID( 0, playerID[16] ) == 33535 ) // id
{
g_Engine.Con_Printf("Right ID\n");
}
else
{
g_Engine.Con_Printf("Wrong ID\n");
}

g_Engine.Con_Printf("%d\n", g_Engine.GetPlayerUniqueID(0, playerID[16]));
// ID = 0

If I have (1, playerID[16]) as parameters, my game will crash so it seems as 0 is the first right parameter but then something isn't right with playerID[16].


Also this prints my real ID:
g_Engine.Con_Printf("%d\n", g_Engine.GetPlayerUniqueID);

// Gets a unique ID for the specified player. This is the same even if you see the player on a different server.
// iPlayer is an entity index, so client 0 would use iPlayer=1.
// Returns false if there is no player on the server in the specified slot.

There is a description from that structure, so I guess it's playerID that is wrong now, probably it prints 0 because it's not defined somewhere else. So that may mean I would need to hook the whole function into this function where I am?
Last edited on
I do not see the definition of the function g_Engine.Con_Printf

but it seems that instead of

g_Engine.Con_Printf("%d\n", g_Engine.GetPlayerUniqueID(0, playerID[16]));

you should specify

g_Engine.Con_Printf("%d\n", g_Engine.GetPlayerUniqueID(0, playerID));
Last edited on
Read my updated post above also.
void (*Con_Printf)( char *fmt, ... );
It is just a message, you print any text you want in the game console.
Also if I do:

g_Engine.Con_Printf("%d\n", g_Engine.GetPlayerUniqueID(0, playerID));

As you said, I get this type of error:

char *playerID[16]
Error: argument of type "char **" is incompatible with parameter of type
" *char"

Also EDIT: I changed playerID[16] to playerID when I now made (0, playerID), still it prints 0 as ID.

EDIT again, g_Engine gets the function, couldn't find anything usable to playerID[16]. So I've no clue now... == number works but it cannot get the real number. I also tried to put playerID once again instead of playerID[16] in (xxx) parameters, it worked if I changed char * playerID[16]; to char playerID[16]; but still prints 0 as ID.
Last edited on
Anyone?
What playerID are you going to print?
Well probably the 2nd parameter ( playerID[16] ), since the first one can only be 0 or 1.

g_Engine.GetPlayerUniqueID( 0, playerID[16] )
You have an array of char pointers of 16 elements. Which one are you going to pass as argument to the function? For example

g_Engine.GetPlayerUniqueID( 0, playerID[0] )

or

g_Engine.GetPlayerUniqueID( 0, playerID[10] )

You may not specify the element playerID[16] because the last acceptable index is 15 (the range of indexes is 0-15)]

Would it differ? Should I test all 16 elemenets then if I'm unsure? Since I don't know which one I need, and what would I do then?
Well if you are saying that 0-15 indexes is only acceptable then I did this,
g_Engine.GetPlayerUniqueID( 0, playerID[16] )
to
g_Engine.GetPlayerUniqueID( 0, playerID[15] )
still it prints 0 as my ID.
So, anyone?
It's undefined behavior. Your program will either crash, it will give you some garbage value or it kill all your goldfishes.
http://en.wikipedia.org/wiki/Undefined_behavior
Okay so it looks like it's not working then.
Topic archived. No new replies allowed.