How would i simultaneously CMP 2 objects? (Solved)

mouse spirit

Well-known member
Im having trouble and was wondering how to both CMP #$52 and #$00 at the same time.
Specifically if both objects are touching the same tile,
then do this. My problem is that if i...
Code:
CMP #$52
BNE  blahblah
CMP #$00
BNE  blahblah


Its like saying yes and no at the same time because its actually right and wrong, so what i need is to be able to say if 52 an 00 are both yes or no.Maybe using BEQs accordingly? But i foresee the same issue with that.
 

dale_coop

Moderator
Staff member
A variable can't be equal to 0 and equal to 52 at the same time!
If it's 0 it's not 52... and if it's 52 it's not 0... right?

Now if you want to check if myVar is 52 or it's 0 (to do something --the same thing-- when it's happening) then the code would be:
Code:
	LDA myVar
	BEQ +doSomething	;; if it's equal to 0 do something
	;; if not
	CMP #$52
	BEQ +doSomething	;; if it's equal to 52 do something
	;; if not 0 and not 52 do something else
	;; here
	JMP +endScript
	
+doSomething:
	;; bla bla bla
	
+endScript:
 

CutterCross

Active member
Unrelated to the actual issue, but CMP #$00 is a little useless. How CMP works is that it subtracts the value of the thing you're comparing to the value the CMP goes with, then it checks if the result is 0. (But it doesn't keep the result of the subtraction, which is an important distinction!) So CMP #$00 subtracts 0 from the value you're comparing it to. Which changes... nothing. Because subtracting 0 gives you the same result.

You can just do something like this without the CMP if you're just checking if a value is 0 or not.
Code:
LDA thing
BEQ +
;;thing is not zero
+
;;thing is zero
 

CutterCross

Active member
Also for your actual question I don't think NESmaker's tile collision tracks if you're colliding with multiple tiles at a time, and only tracks the most recent tile you collide with, but I could be wrong here.

*EDIT: I was misreading what you were trying to check. Whoops ;P
 

dale_coop

Moderator
Staff member
Checking if 2 objects touching the same tile... hmmm, I don't really see how to do that easily with nesmaker.
For each object, the tile script is executed: once for the 1st object and another time for the 2nd object.
But's not the tile that is checking if there is an object colliding to it... it's the object that is checking which tile is colliding and executes that tile script.
 

mouse spirit

Well-known member
I dont think my last 2 responses post. Just incase. Thank you both very much. Secondly,
What if i create 2 variables at value 0, if object A or B is currently touching the tile,change their variable to 1.
Now check if both variables are at 1, then do code?
 

dale_coop

Moderator
Staff member
Yes, it could work.
And you also need to to set those variable to 0 when the objects don't touch the tile anymore ;)
 

mouse spirit

Well-known member
Understood. I will try this out. Thank you both. And yeah, changing the variable when not touching sounds tougher. As it seems tiles check when touched.
 

mouse spirit

Well-known member
I ended up being able to use one variable. I will keep this in mind for the future though,thank you.
http://nesmakers.com/viewtopic.php?f=35&t=5522
 

mouse spirit

Well-known member
Juat replying here incase someone wonders about this. Use variables instead of trying to CMP 2 things touching the same tile. As you can CMP 1 thing at a time.
 
Top Bottom