Problems with && and ||

Im having some strange issues with && and ||

In one instance, for example, the following code:

(players starts off at 0,0 and wants to move to a further point, say 100,100)

if ((movetox!=playerx) && (movetoy!=playery))  {
<playerx and player increased if needed>

Which will work fine until the playerx OR playery hit movetox/movetoy

if ((movetox==playerx) && (movetoy==playery))  { }
else {
<playerx and player increased if needed>
works fine all the time? (i can get the code to work like that, but i dont like it)
later on, i have

if ((shotx[s]==shotgox[s]) && (shoty[s]==shotgoy[s])) { shots[s]=0; }

which basically kills off a bullet when it reaches it destination
but it doesnt seem to register at all when the variables hit 0
if i change the && to || itll work, but will kill a bullet when any axis is correct, rather than both

its been happening all over the place.

The whole code is a bit much, but ill try and replicate it into something smaller if i can and post that
I have absolutely no idea whats going on :(

THanks in advance
Who is Participating?
zzynxConnect With a Mentor Software engineerCommented:
Some logic:

The inverse of

[1] if ( a==A && b==B )

                                                  with inverse I mean:  if ( !(a==A && b==B) )


[2] if ( a!=A || b!=B )        

Look at this table to understand:
a =    A   A  C  C
b =    C   B   B  C

[1] =  0   1   0  0
[2] =  1   0   1  1

But maybe that's not your problem.
hippydazAuthor Commented:
ok, ignore the

if ((shotx[s]==shotgox[s]) && (shoty[s]==shotgoy[s])) { shots[s]=0; }

problem, that was just me being an idiot

the primary != && != problem still remains however
hippydazAuthor Commented:
My problem is that im an idiot :/

That worked zzynx, ta, points to you.

I dont see why it works, offhand, ill have a look later and try and understand.

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Well I am lost in your explanation butr basically;

If you have a && b - it is true only if a and b are true together
|| needs one of the arguments to be true so that it is true

What exactly you need?
I knew I have slow internet today:)
Glad that you already solved the trouble
zzynxSoftware engineerCommented:
Thanks for accepting.
That keeps us going on.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.