Objects not being created

baardbi

Well-known member
This is a weird one. The pickup objects in HandleDrops.asm are not being created, but the CreateObject for monster death works fine. I also want another object to be created when a boss is defeated, but that object isn't created either. The code works, in the sense that it jumps to the right place. I know that since the music stops playing (it's supposed to do that). I was wondering if this has anything to do with object slots or something like that (not enough free slots or something...).

Here's my HandleDrops.asm code:

Code:
;;; monster objects drop at random.
	LDA otherCenterX
	SBC #$08
	STA temp
	LDA otherCenterY
	SBC #$08
	STA temp1
	
	LDA Object_scroll,x
	SBC #$00
	STA temp3

    ;; if on the BOXEY PETE screen
    LDA currentScreen
    CLC
    CMP #BOXEY_PETE_SCREEN
    BNE notBoss

boxeyPeteDropsClue:
	;; Boxey Pete is defeated and drops a clue.
	StopSound
	
	LDA #$01
	STA ignoreControls
	
	CreateObject temp, temp1, #BOSS_DROPS_CLUE, #$00, temp3
	JMP donePickup
notBoss:
	;JSR GetRandomNumber
	LDA #$00 ;   <- **************** Bårds dirty hack :) :) :) ******************
	;AND #%00000011 ;; now, we have a number between 0 and 3
	BNE pickup1 ;; 
pickup0:
	;;; Pickup 0: Here, we'll create health
	CreateObject temp, temp1, #HEALTH_PICKUP, #$00, temp3
	JMP donePickup
pickup1:
	CMP #$01
	BNE pickup2
	;;; Pickup1: Here, we'll create nothing :)
	JMP donePickup
pickup2:
	CMP #$02
	BNE pickup3
	;;; Pickup1: Here, we'll create nothing :)
	JMP donePickup
pickup3:
	;;; Pickup1: Here, we'll create nothing :)
	JMP donePickup
	;;;; do the same for each case.
	;;;; blank cases will simply return 'nothing'.
	
donePickup:	
	;;; ALL cases create a "pow"
	CreateObject temp, temp1, #OBJ_MONSTER_DEATH, #$00, temp3

Here are my game objects:

gameobjects.png


Here are my user variables:

uservariables.png


And here are my user constants:

userconstants.png
 

dale_coop

Moderator
Staff member
Could it be the pickup is create at the same place (or very very close) than your player... so when it's created, it's directly collected by your player?
You should try to create it at another position to see if it 's that.. to make your object non "pickup" and see if it's created correctly at the right spot.
 

baardbi

Well-known member
Thanks for the tip Dale, but it can't be this. I'm shooting enemies from far away, so I am very sure that the player isn't directly collection the items. I just find it strange that some objects are created and some are not. When I think back, I have had a problem with creating pickup items from the beginning... Maybe I need to check if I changed some scipts when I started making this game.
 

dale_coop

Moderator
Staff member
Oh ok... then, if it's when shooting... it might be the code that destroys the pickup object created instead of the projectile object. You might have an error in your MonsterHurt script. Could you share it?
 

baardbi

Well-known member
Hmm. I think you may be on to something here. That makes sense.

Here is my HandleHurtMonster.asm:

Code:
;;; what should we do with the monster?
        ;;; monster is loaded in x
        LDA Object_vulnerability,x
        AND #%00000100 ;; is it weapon immune?
        BEQ notWeaponImmune
        ;PlaySound #SFX_MISS
        JMP skipHurtingMonsterAndSound
    notWeaponImmune:
        
        LDA Object_status,x
        AND #HURT_STATUS_MASK
        BEQ dontskipHurtingMonster
        JMP skipHurtingMonster
    dontskipHurtingMonster:
        LDA Object_status,x
        ORA #%00000001
        STA Object_status,x
        LDA #HURT_TIMER
        STA Object_timer_0,x
        ;;; assume idle is in step 0
        ChangeObjectState #$03,#$02 ;;Code changed by baardbi from original state 01 to new state 03
									;;to match monster hurt reaction
        ;;;; unfortunately this recoil is backwards
        LDA Object_status,x
        AND #%00000100
        BNE skipRecoilBecauseOnEdge
        LDA Object_vulnerability,x
        AND #%00001000 
        BNE skipRecoilBecauseOnEdge ;; skip recoil because bit is flipped to ignore recoil
        
        LDA selfCenterX
        STA recoil_otherX
        LDA selfCenterY
        STA recoil_otherY
        LDA otherCenterX
        STA recoil_selfX
        LDA otherCenterY
        STA recoil_selfY
        JSR DetermineRecoilDirection
    skipRecoilBecauseOnEdge:
        LDA Object_health,x
        SEC
        SBC #$01
        CMP #$01
        BCC +
		JMP notMonsterDeath
	+

        DeactivateCurrentObject
        PlaySound #SND_SPLAT
        ;;;;;;;;;;;;;;;;;; ok, so now we also add points to score
        ;LDY Object_type,x
        ;LDA ObjectWorth,y
        ;STA temp
;       AddValue #$03, GLOBAL_Player1_Score, temp
                ;arg0 = how many places this value has.
                ;arg1 = home variable
                ;arg2 = amount to add ... places?
        ;; and this should trip the update hud flag?
        
        ;;;; 
    

	TXA
	STA tempx

	AddValue #$08, myScore, #$01, #$00

	;STA hudElementTilesToLoad
	;	LDA #$00
	;	STA hudElementTilesMax
		; LDA DrawHudBytes
		; ora #HUD_myScore
		; STA DrawHudBytes
	UpdateHud HUD_myScore
	LDX tempx
	TXA
	STA tempy

	AddValue #$08, myScore, #$01, #$00

	;STA hudElementTilesToLoad
	;	LDA #$00
	;	STA hudElementTilesMax
		; LDA DrawHudBytes
		; ora #HUD_myScore
		; STA DrawHudBytes
	UpdateHud HUD_myScore
	LDX tempy

        JSR HandleDrops
        JSR HandleToggleScrolling
		
		CountObjects #$00001000, #$00
		BEQ +
		JMP ++
	+
		.include SCR_KILLED_LAST_MONSTER
	++
        
        JMP skipHurtingMonster
    notMonsterDeath
        STA Object_health,x
    skipHurtingMonster: 
        ;PlaySound #SFX_MONSTER_HURT
    
    skipHurtingMonsterAndSound:
        LDX tempx
        ;; what should we do with the projectile?
        DeactivateCurrentObject
 

dale_coop

Moderator
Staff member
Ok, try with that one:

Code:
;;; what should we do with the monster?
        ;;; monster is loaded in x
        LDA Object_vulnerability,x
        AND #%00000100 ;; is it weapon immune?
        BEQ notWeaponImmune
        ;PlaySound #SFX_MISS
        JMP skipHurtingMonsterAndSound
    notWeaponImmune:
        
        LDA Object_status,x
        AND #HURT_STATUS_MASK
        BEQ dontskipHurtingMonster
        JMP skipHurtingMonster
    dontskipHurtingMonster:
        LDA Object_status,x
        ORA #%00000001
        STA Object_status,x
        LDA #HURT_TIMER
        STA Object_timer_0,x
        ;;; assume idle is in step 0
        ChangeObjectState #$03,#$02 ;;Code changed by baardbi from original state 01 to new state 03
									;;to match monster hurt reaction
        ;;;; unfortunately this recoil is backwards
        LDA Object_status,x
        AND #%00000100
        BNE skipRecoilBecauseOnEdge
        LDA Object_vulnerability,x
        AND #%00001000 
        BNE skipRecoilBecauseOnEdge ;; skip recoil because bit is flipped to ignore recoil
        
        LDA selfCenterX
        STA recoil_otherX
        LDA selfCenterY
        STA recoil_otherY
        LDA otherCenterX
        STA recoil_selfX
        LDA otherCenterY
        STA recoil_selfY
        JSR DetermineRecoilDirection
    skipRecoilBecauseOnEdge:
        LDA Object_health,x
        SEC
        SBC #$01
        CMP #$01
        BCC +
		JMP notMonsterDeath
	+

        DeactivateCurrentObject
        PlaySound #SND_SPLAT
        ;;;;;;;;;;;;;;;;;; ok, so now we also add points to score
        ;LDY Object_type,x
        ;LDA ObjectWorth,y
        ;STA temp
;       AddValue #$03, GLOBAL_Player1_Score, temp
                ;arg0 = how many places this value has.
                ;arg1 = home variable
                ;arg2 = amount to add ... places?
        ;; and this should trip the update hud flag?
        
        ;;;; 
    

	TXA
	STA tempy

	AddValue #$08, myScore, #$02, #$00

	;STA hudElementTilesToLoad
	;	LDA #$00
	;	STA hudElementTilesMax
		; LDA DrawHudBytes
		; ora #HUD_myScore
		; STA DrawHudBytes
	UpdateHud HUD_myScore
	LDX tempy

        JSR HandleDrops
        JSR HandleToggleScrolling
		
		;; check all monsters killed:
		CountObjects #%00001000, #$00
		LDA monsterCounter
		BEQ +
		JMP ++
	+
		.include SCR_KILLED_LAST_MONSTER
	++
        
        JMP skipHurtingMonster
    notMonsterDeath
        STA Object_health,x
    skipHurtingMonster: 
        ;PlaySound #SFX_MONSTER_HURT
    
    skipHurtingMonsterAndSound:
        LDX tempx
        ;; what should we do with the projectile?
        DeactivateCurrentObject
 

baardbi

Well-known member
Wow! So cool! Thank you! It works now (with random drops). I am a little curious how you managed to solve this. But now I just have another problem I have to solve :) The character is stuck in the hurt animation after a pickup (but can still move), until I shoot. Then the animation is back to normal.
 

dale_coop

Moderator
Staff member
No problem.
The issue was your script was messing around with the "tempx" variable.
This variable should not be changed in any scripts from the collision engine... except on the main loop itself. That variable constaints the index of the object instance currently being checked agains other objects (in this handle monster hurt script, tempx designates the player weapon or player projectile.
In your script it was modified (STA tempx) in the middle of the monster hurt script... I just modified it to "tempy" (this variable is not used in the loop, so it's free to use).
(Also, I clean up and removed some duplicate code --increase score and update hud... but not related to your issue).
 

baardbi

Well-known member
Awesome! I'm getting better at assembly every day, and much of that is because you share your knowledge. Thank you for teaching me this stuff :)
 
Top Bottom