Jump to content
MrIslomaniac

Simple C++ question

Recommended Posts

Why doesn't this work?

if (atoi(GetEntityKey(Entity,"Value1","NULL")) >= atoi(GetEntityKey(entity,"Value2","NULL"))){

Left side contains 30, right side 20, but it doesn't work -.-

Any idea?

 

Thanks

Share this post


Link to post

What's not working precisely? The conversion from string to int? Is GetEntityKey returning NULL? A little more info would be nice!

 

Cheers!

Share this post


Link to post

no that works correctly, atoi(GetEntityKey(Entity,"Value1","NULL")) returns 30 and atoi(GetEntityKey(Entity,"Value2","NULL")) returns 20

but this if is not working

if (atoi(GetEntityKey(Entity,"Value1","NULL")) >= atoi(GetEntityKey(entity,"Value2","NULL"))){
return 1
}
else
return 0

always returns 1

even if left side is 0 and right side is 30 ...

another example that does not work:

0 >= 0

Share this post


Link to post

another example that does not work:

0 >= 0

 

Well, that should evaluate to true (return 1)... 0 is after all, equal to 0.

 

Secondly, is that code copied/pasted? Your second atoi statement has a lowercase 'e' on the entity, which could cause it to bring back a zero... In which case, only a negative number on the LHS can cause an evaluation of false

Share this post


Link to post

No, just wrong typing, sorry =(

if (atoi(GetEntityKey(entity,"Value1","NULL")) >= (atoi(GetEntityKey(entity,"Value2","NULL")))){
printf("LOLOLOL\n");
}

Sometimes it works, sometimes it does not ...

Examples:

1 >= 58

well as i said sometimes it doesn't work with any number, sometimes it works perfectly...

 

//EDIT

found a way to get it working, when i store atoi(GetEntityKey(entity,"Value2","NULL")) in an int variable right before i do the if statement, it works =)

thanks for your help

 

Dustin

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...