[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Problems with && and ||

Posted on 2004-04-01
6
Medium Priority
?
219 Views
Last Modified: 2012-05-04
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
Whereas

**
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
0
Comment
Question by:hippydaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 

Author Comment

by:hippydaz
ID: 10732212
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
0
 
LVL 37

Accepted Solution

by:
zzynx earned 300 total points
ID: 10732214
Some logic:

The inverse of

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

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

is

[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.
0
 

Author Comment

by:hippydaz
ID: 10732255
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.

Thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Venabili
ID: 10732279
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?
0
 
LVL 20

Expert Comment

by:Venabili
ID: 10732300
I knew I have slow internet today:)
Glad that you already solved the trouble
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10732311
Thanks for accepting.
That keeps us going on.
:)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question