going insane with conditionals

digit2600

Member
nothing says "I'm a total noob to this language " like not being able to write a freakin' conditional that would be cake in any other language. ..

I've Been working for days trying to tweak a castlevania /ninja gaiden/typical action platformer melee script and I've got most of it working except one last annoying problem. ... which I could solve. .. in any other language.

here's what I got:

cmp #$03 ; attacking state
Beq cannot move

cmp #$01; walking state
beq can move

cmp #$02; jumping state
beq can move

changeObjectstate....
--------
ok. this works fine, however, when I jump up and attack, I want to branch to the can move state..

normally I'd write it like this:
if (attacking){
if (walking && !jumping ){ cantMove}else {canMove}

basically, how would I translate that logic ?

I've tried
cmp attack
beq cantmove
cmp walking
beq can Move
cmp jumping
beq can Move
cmp attack
and walking
and jumping
can Move

am I totally wrong here ?
 

chronosv2

New member
As has been mentioned before, conditional statements are tricky in 6502 or any other "direct-to-processor" language.

So the first thing that I'm thinking is your number... is this intended to be a bitfield?
i.e. if you're moving does it set one bit and if you're jumping it sets another?

Code:
; Moving = #%00000001
; Jumping = #%00000010
; Attacking = #%00000100
LDA PlayerState
AND #%00000001
CMP #%00000001; Are we moving?
BNE +MovingCheckJump ;We are. Let's check jumping.
LDA PlayerState ;We're not so let's check jumping without moving
AND #%00000010
CMP #%00000010
BNE +JumpingCheckAttack
LDA PlayerState ;Not jumping either. Check for stationary attack.
AND #%00000100
CMP #%00000100
BNE +StationaryAttack
; And so on and so forth, checking for each possibility

Etc.
You've got to check for each possibility, as far as I'm aware.
So check Moving
If so check Moving+Jumping
If so check Moving+Jumping+Attacking
If not Moving+Jumping check Moving+Attacking
If not Moving check Jumping
If Jumping check Jumping+Attacking
If not jumping check Attacking
If so we're stationary attacking.

I could be very far off-base, what with my 1 week 6 days of experience, but this is how I've come to understand things in my time with Assembly.
 

digit2600

Member
so, I don't know if I need to use the bitfields to represent states to compare - but if not then, would this make sense?;

lda walking
and jumping
and attacking
cmp jumping
bne can't move
can move
move player right
can't move
face right
rts


does this logic and syntax seem correct?
 

MistSonata

Moderator
I think maybe the problem is that you're trying to tell it to allow you to move so long as you're in the air, but the action steps themselves don't determine that. Even if you could do the conditional the way you want to, it wouldn't work, because an object can only be in one state at a time. If an object is in the "walking" state, it can't be in any other state, so checking for "If walking and not jumping" doesn't make sense, because so long as you're in the walking state you can't ALSO be in the jumping state.

To solve this, you need to be able to determine whether or not you're in the air, say with a variable that the physics script sets when the player lands, and resets when you use a jump script. Then you could try something like this:

Code:
LDA Player1_InAir
BEQ can move ;; if InAir variable =0 then player is in air, and can always move
LDA playerobjectstate ;;(I forgot how to call the object state, you should be able to do it in a macro, I think)
CMP  #$03 ; attacking state
BEQ can't move
;; otherwise, can move

Hope this helps
 

digit2600

Member
hmmm, that's weird, because since the melee script was written for the adventure module, ' had to tweak it to work on the platformer. ..

it didn't stop the player in the platform module, so my solution was to do a
cmp #$03
Beq can't move in the walking script

if I remove that, player can attack and move.

do you know where variables and macros are stored so I can better freak with these?
 

MistSonata

Moderator
The code I posted checks for the inAir variable first, and has it branch to "can move" if you're in the air, thus bypassing the cmp attacking check only if the player is in the air. The only way it'll go to "can't move" is if you're on the ground AND attacking. So yeah, no need to delete that check, just have it bypass it if your player is in the air.

I know the macros are stored in GameEngineData\Routines\System\macros.asm, and the variables are stored in a few places (just do a search in file explorer for "variables" and the scripts for them should pop up). You can also create variables in the tool in the project settings.

If you're looking to modify the platformer physics and collision code, they're in GameEngineData\Routines\System\SCRIPTS\. Just remember to back them up first so you can easily restore them if something goes wrong.
 

digit2600

Member
awesome, thanks mist, this helps immensely. i wasn't sure if that in air var was a actual var or an example.

gonna give this a shot when I get home. thanks so much !
 
Top Bottom