Experience system

SoulBlayzR

New member
Hello everyone, I just want something simple for my game. I want an experience system, where, if I collect 100 points, they'll all go away and you'll gain a level. Kind of how lives work in Super Mario Bros. I've tried doing this myself in ASM but I got confused halfway through and got stuck. Could someone help a guy out?

Here's the code I attempted
Code:
    LDA myScore
    CLC
    CMP #$64
    BCS levelUp
    
    levelUp:
    TXA
    STA tempx
    SBC myScore,#$64
    LDA myScore
    
    LDX player1_object
    STA Object_score.x
    
    INC myKeys
    LDA myKeys
    
    LDX player1_object
    STA Object_keys.x

Results: nothing happens upon gaining 100 EXP
 

MistSonata

Moderator
Here's a quick attempt with some notes.

Code:
    LDA myScore
    ;; You don't need to clear or set the carry flag for a CMP
    CMP #$64
    BCS levelUp
    ;; You should put either an RTS here or a JMP that directs the code to the end of this script, otherwise you'll level up no matter what
    RTS
    
    levelUp:
    ;; no need to SEC here, since we know that the script will only branch here if the carry is already set. 
    SBC #$64 
    STA myScore ;; I'm going to assume here that the LDA was supposed to be an STA
    
    STX tempx ;; STX will store the value that's in the X register, just as STA would with the accumulator. This way you don't have to LDA myScore again. Also, moved it down here so the STX doesn't mess with the carry flag.
    LDX player1_object
    STA Object_score, x
    
    INC myKeys
    ;; player1_object is already loaded into X, no need to repeat it.
    INC Object_keys, x ;; It's easier to just INC them both if all you need is to add one to both.
    
    LDX tempx ;; make sure you restore tempx to the X register
    
    RTS

I should note that unless there's a particular need for it that I'm not seeing, there's really no sense in having the Object_score and Object_keys variables in there. Those kind of indexed variables are best for things that all objects use. Unless the monsters and other objects are supposed to get keys or gain experience, there's not much point in it.
 

SoulBlayzR

New member
Hmm, it still doesn't appear to be working.

Is it because I'm storing it as a separate script, and it needs to be called? Sorry for these questions, I'm a bit of an ASM noob...
 

dale_coop

Moderator
Staff member
When you test/check hud variables, if you want to test tenth :
Code:
   LDA myScore+1
    CLC
    CMP #$01
    BCS levelUpAt10
if you want to test hundreds:
Code:
   LDA myScore+2
    CLC
    CMP #$01
    BCS levelUpAt100

etc...

cf that post: http://nesmakers.com/viewtopic.php?f=35&t=2061
 

dale_coop

Moderator
Staff member
What are Object_score, x and Object_keys, x
(object variables you added in your project?)
You have score and key by players? Maybe multiple players?
 

SoulBlayzR

New member
So after a while I realised that I could use JSR to jump to the routine that I need to execute the level up instructions, but NES Maker is returning an error about an unknown label. I don't understand why, the other scripts that HandleHurtMonster is JSRing to don't have labels either...?
 
Top Bottom