How to make pickups stay gone?

Holmfry

Member
Hi there! I'm working on a game with the MazeBase. I'm building it in such a way that you can return to screens multiple times if you want. Some screens have a treasure pickup on them. When you pick this up and leave the screen and then return, it's back. I'm trying to figure out how to make it stay gone.

I've tried making it an object instead of a "prize" collision tile, tried giving it persistence (which of course only makes it stay forever) etc. Does anyone know the best approach to save the fact that this treasure pickup has already been picked up when reloading the screen it was on?

Thanks!
 

Logana

Well-known member
I have an idea, so Instead of having the treasure be a tile you could make it a sprite like you said you did before and edit the code to make the screen trigger, making sure you give each screen with a collectible a different trigger and then you can make sure it’s still gone when you come back
 

Holmfry

Member
OK so I got it to stay using the trigger as you suggested. The object disappears and stays gone, so thanks for that! I edited the default pickup script. However I can't get it to add a value, update my hud element or play the sound. The TriggerScreen entry does run though so I know it's going through this code. I also tried changing the values from #$0x to hard-coded numbers and that didn't work either. What am I doing wrong? (Note, my HUD element to update is, in fact 3 and I'm trying to add 100 points to myScore). Thank you!


;;; 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.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pickupLabel:
LDA Object_type,x
CMP #$01 ;;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.
;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?

AddValue #$06, myScore, #$1, #$02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;; Do we need to update the HUD to reflect this?
;;;;;;;;;;;;;;;;;;;;;;;;; If so, which element is the above variable represented in?
UpdateHudElement #$03

PlaySound #sfx_cursor
TriggerScreen screenType

JMP +endPickups
+notThisPickup:


+notThisPickup

+endPickups

;;; object will already destroy based on type.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 

Logana

Well-known member
Is your score the 4th hud element? Also you need to ad an RTS at the end, it should work
 

Holmfry

Member
Yeah, my score is the 4th hud element. I'll try the RTS thing, I'm not sure what that is. Put it after the last line?

Edit: OK I looked up what RTS is, makes sense. However when I added it at the end, my game crashes when I get the pickup.
 

Logana

Well-known member
strange, idk maybe try to use INC MyScore instead of add value, idk why the sfx wouldn't be working
 

Jonny

Well-known member
I can't see that anything is wrong here. If you're using a sprite HUD you do not need to UpdateHudElement but you do for a normal HUD. This is snippet of my pickups script which uses the AddValue macro the same as you're doing...

Code:
;;; PICKUPS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    LDA Object_type,x                 ;; COMPARE TO THIS  ;;
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
;;; RED DIAMOND PICKUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    CMP #$06                          ;; DIAMOND OBJECT?  ;;
    BNE notRedDiamond                   
    PlaySound #$07
    AddValue #$03, myScore, #1, #$02  ;; ADD 100 TO SCORE ;;
    ;LDA #$00
    ;STA tempC
    ;JMP pickupEffect
notRedDiamond:
 

Holmfry

Member
OK thanks guys! What the heck. I'm so confused. Even more confusing is the fact that the trigger line works but apparently none of the other code does, even though it's in the same block. If I figure out why I'll update this thread. Thanks again for taking a look!
 

Jonny

Well-known member
You could also check the order of your macros. Try having your PlaySound and TriggerScreen before AddValue instead of after. You could also try commenting them out just for testing elimination purposes.
 

Holmfry

Member
Thanks Jonny! I tried changing the order, and also reverting the entire pickup script back to the default that game with the mazebase. It doesn't work even as the default, the score doesn't get incremented.
 

Holmfry

Member
Maybe it's this line?
CMP #$01 ;;What object is your pickup? 00 - 0f

How do you know what object your pickup is?

Although if that were the problem then I imagine the TriggerScreen wouldn't work either.. and it is.

Edit: Nope, that's not it, after some testing #$01 is definitely correct.
 

Holmfry

Member
OK I got it working! If I take the AddValue, Playsound etc outside of the CMP block, then it works. Since I only have one kind of pickup in my game, this suits me fine. But not sure why the CMP wasn't resolving... or how in the world the TriggerScreen was working since it was also in that same block. If anyone has any ideas on that I'd still love to know just for educational purposes! :)

Thank you all!
 

Holmfry

Member
EDIT: for anyone else who runs into this - I had made my treasure pickups and heart pickups in the Monsters section. Never even looked at the Game Objects folder!! I'm such a silly goose. There are exactly 0f objects in there so I've no doubt it'll work once I recreate the objects in their proper folder. :) Edit 2: Yup, it worked!!



@Jonny possibly n00b question - how do you know your diamond object is #$06? I've added multiple pickup types to my game so now I have to figure out the issue with my CMP.

Here's my latest code.. there's a Treasure pickup, and a heart pickup. I've tested the chestPickup and heartPickup section individually and they both definitely work, I've narrowed it down to that CMP doesn't ever match. The notes in the NesMaker template for the pickup script say the object can be 00 - 0f but I literally tried all of those values and my treasure pickup doesn't match.

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.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_type,x
CMP #$01 ;;What object is your pickup?  00 - 0f
BNE +notThisPickup
JMP chestPickup
+notThisPickup
CMP #$02
BNE +notThisPickup
JMP heartPickup
+notThisPickup
JMP +endPickups

chestPickup:
;;;;;;;;;;;;;;;;;;;;;;;;; What do you want to do to the value?
;;;;;;;;;;;;;;;;;;;;;;;;; Increase?  Decrease?  Set it to a number?
;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?
AddValue #$03, myChests, #$4, #$00  ;add to treasure chest percentage;
AddValue #$06, myScore, #$3, #$03  ;add to score;
AddValue #$06, myScore, #$5, #$02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;; Do we need to update the HUD to reflect this?
;;;;;;;;;;;;;;;;;;;;;;;;; If so, which element is the above variable represented in?
UpdateHudElement #$05
UpdateHudElement #$03
PlaySound #sfx_Treasure
TriggerScreen screenType
JMP endPickups

heartPickup:
INC myLives  ;add to lives
UpdateHudElement #$00
PlaySound #sfx_Cursor
TriggerScreen screenType
JMP +endPickups

endPickups:


;;; object will already destroy based on type.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
Last edited:

Jonny

Well-known member
@Jonny possibly n00b question - how do you know your diamond object is #$06? I've added multiple pickup types to my game so now I have to figure out the issue with my CMP.
Your Game Objects start #$00 which is your player object and goto #$0F (15 in decimal) after that you are into your Monster Objects which continue on from the Game Objects so #$10 onwards (16). I put a prefix on the names of all mine, just find it quicker... so for example I name " (#$06) Diamond " for that diamond pickup. You don't obviously have to do that, i just find it easer. Hope that helps.
 

Kanbei85

Member
I have an idea, so Instead of having the treasure be a tile you could make it a sprite like you said you did before and edit the code to make the screen trigger, making sure you give each screen with a collectible a different trigger and then you can make sure it’s still gone when you come back

I have exactly this same problem, but I'm using the screen trigger to unlock access to the pickup. Which means I cannot use a screen trigger to solve this dilemma. What I need is a second-level trigger for this screen! Like Trigger_1 and then if you trigger again, Trigger_2.

Or something like that. Clearly, we need to figure out a way to make pickups stay gone.

I thought about UN-triggering the screen with the pickup, but that still creates an endless loop because the player could then simply re-trigger the screen to get the powerup again. This is, again, a pretty big deal!

For now, I guess I have no choice but to change my game to work around this limitation and make the powerup trigger the screen.
 
Last edited:

Logana

Well-known member
I have exactly this same problem, but I'm using the screen trigger to unlock access to the pickup. Which means I cannot use a screen trigger to solve this dilemma. What I need is a second-level trigger for this screen! Like Trigger_1 and then if you trigger again, Trigger_2.

Or something like that. Clearly, we need to figure out a way to make pickups stay gone.

I thought about UN-triggering the screen with the pickup, but that still creates an endless loop because the player could then simply re-trigger the screen to get the powerup again. This is, again, a pretty big deal!

For now, I guess I have no choice but to change my game to work around this limitation and make the powerup trigger the screen.
You could make the sprite spawn on a variable, and when you collect that sprite it changes the variable to like 0 and when you com back it checks for the byte, and it won’t draw, just a random idea
 

Kanbei85

Member
You could make the sprite spawn on a variable, and when you collect that sprite it changes the variable to like 0 and when you com back it checks for the byte, and it won’t draw, just a random idea
I'm afraid I don't know enough to know how to actually do what you just said ;)
 
Top Bottom