Help with item pick add number to HUD

DarthAT

Member
Working on a Currency item pick / monster drop this morning. I have taken pieces from the maze tutorial prize code and added to the templet pickup script in my adventure base. It seems to be working, but when I pick up the item the math is not working out. For example, the following code adds 6 to my total (if I change arg3 to 01, it adds 15... what am I doing wrong? (For now I would like it to increment by 1 only)
Code:
    LDA Object_type,x
    CMP #$07 ;;What object is your pickup?  00 - 0f
    BNE +notThisPickup
        ;;;;;;;;;;;;;;;;;;;;;;;;; What do you want to do to the value?
        ;;;;;;;;;;;;;;;;;;;;;;;;; Increase?  Decrease?  Set it to a number?
        ;;;;;;;;;;;;;;;;;;;;;;;;; Here, we are setting myAmmo to 5.
        LDA #$05
        STA myCurrency
            CPX player1_object
    ;MACRO AddValue arg0, arg1, arg2, arg3
    ;arg0 = how many places this value has.
    ;arg1 = home variable
    ;arg2 = amount to add
    ;arg3 = what place value is receiving the addition?
        ;;; 0 = ones place, 1 = tens place, 2 = hundreds place, etc.
    
    AddValue #$05, myCurrency, #$1, #$00
    UpdateHudElement #$03
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;;;;;;;;;;;;;;;;;;;;;;;; Do we need to update the HUD to reflect this?
        ;;;;;;;;;;;;;;;;;;;;;;;;; If so, which element is the above variable represented in?
    +notThisPickup:

            JMP +endPickups
    +notThisPickup:

    CMP #$03
    BNE +notThisPickup

Thank you for any help you can provide.
 

Pauldalyjr

Active member
Working on a Currency item pick / monster drop this morning. I have taken pieces from the maze tutorial prize code and added to the templet pickup script in my adventure base. It seems to be working, but when I pick up the item the math is not working out. For example, the following code adds 6 to my total (if I change arg3 to 01, it adds 15... what am I doing wrong? (For now I would like it to increment by 1 only)
Code:
    LDA Object_type,x
    CMP #$07 ;;What object is your pickup?  00 - 0f
    BNE +notThisPickup
        ;;;;;;;;;;;;;;;;;;;;;;;;; What do you want to do to the value?
        ;;;;;;;;;;;;;;;;;;;;;;;;; Increase?  Decrease?  Set it to a number?
        ;;;;;;;;;;;;;;;;;;;;;;;;; Here, we are setting myAmmo to 5.
        LDA #$05
        STA myCurrency
            CPX player1_object
    ;MACRO AddValue arg0, arg1, arg2, arg3
    ;arg0 = how many places this value has.
    ;arg1 = home variable
    ;arg2 = amount to add
    ;arg3 = what place value is receiving the addition?
        ;;; 0 = ones place, 1 = tens place, 2 = hundreds place, etc.
   
    AddValue #$05, myCurrency, #$1, #$00
    UpdateHudElement #$03
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;;;;;;;;;;;;;;;;;;;;;;;; Do we need to update the HUD to reflect this?
        ;;;;;;;;;;;;;;;;;;;;;;;;; If so, which element is the above variable represented in?
    +notThisPickup:

            JMP +endPickups
    +notThisPickup:

    CMP #$03
    BNE +notThisPickup

Thank you for any help you can provide.
Remember this math is in hex, so #$1 =16, #$01 would equal 1. Also you have 5 places for your value, do you want it that many digits? And looks like you CMP to item #$07 but are using #$05,is that in purpose?
 

DarthAT

Member
Thanks for your imput and keen eye! It helped get this working.
Here is my finished code that has 3 items worth; 1, 5, and 10 gems.

Code:
;;; Pickup scripts.
;;; Right now, we need to look at the type of object that is in X.
;;; Then, we have to do pickup behavior accordingly.

;; Here is an example of how to set variable myAmmo to 5 if the pickup type
;; is gameobject 2.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    LDA Object_type,x
    CMP #$07 ;;What object is your pickup?  00 - 0f
    BNE +notThisPickup
        LDA #$07
    ;MACRO AddValue arg0, arg1, arg2, arg3
    ;arg0 = how many places this value has.
    ;arg1 = home variable
    ;arg2 = amount to add
    ;arg3 = what place value is receiving the addition?
        ;;; 0 = ones place, 1 = tens place, 2 = hundreds place, etc.   
    AddValue #$04, myCurrency, #$01, #$1
    UpdateHudElement #$03
    
        JMP +endPickups
    
+notThisPickup:
    
    LDA Object_type,x
    CMP #$08
    BNE +notThisPickup
        LDA #$08
        AddValue #$04, myCurrency, #$05, #$0
        UpdateHudElement #$03
        JMP +endPickups

+notThisPickup:

    LDA Object_type,x
    CMP #$09
    BNE +notThisPickup
        LDA #$09
        AddValue #$04, myCurrency, #$01, #$0
        UpdateHudElement #$03
        JMP +endPickups
+notThisPickup:

+endPickups
 
Top Bottom