Language…
9 users online: Angel Miranda,  BD_PhDX, Bonobi, drkrdnk, Klug,  LMNtals, MorrieTheMagpie, SMB2J-2Q, Xulon - Guests: 144 - Bots: 77
Users: 68,449 (2,269 active)
Latest user: Liamo82

%set_item_memory() adding unusual behaviors

Hi. It may not be directly because of the use of %set_item_memory(), but when I add it to my CoinHunt coin and insert it with GPS, it acts like a solid question block from below - one with wings, a p-balloon, or key in it it seems. This happens whether or not I use it as an object, so I don't think it has to do with ObjecTool. I've tested it and, simply removing %set_item_memory() 'fixes' the issue, while also disabling Item memory, obviously not what I want. The code for the coin is below, with the only changes I've made to it being to add %set_item_memory and set the !FreeRAM.

Code
;The custom coin.
;Set it to act like tile 25 for more stable results.

db $42
JMP Work : JMP Work : JMP Work : JMP Return : JMP Return : JMP Return : JMP Return : JMP Work : JMP Work : JMP Work

;PLEASE NOTE: if you're going to mess with the values below, you must change them on all the other blocks related to this one as well!

	!Coins = 8		;Needed amout of custom coins (decimal!)
	!EmptyRAM = 5C		;Empty RAM adress for the custom coin counter ; originally 79


Work:
	PHY
	JSR Glitter	;Show glitter
	PLY
	PHY
	LDA #$02 	;Replace with block 25
	STA $9C
	JSL $00BEB0 	;Make the block disappear
	PLY
	INC $13CC	;Increment coin counter. Remove this line if you don't need it\
        %set_item_memory()

	LDA $!EmptyRAM
	CMP #$FF	;Counter won't reset if you get 256 coins
	BEQ Return
	INC $!EmptyRAM	;Increase !EmptyRAM counter
	LDA $!EmptyRAM
	CMP #!Coins	;Play correct SFX if total needed coins number reached
	BEQ SFX
	LDA #$01	;\Play "coin" SFX. Go http://smwc.me/t/6665 to
	STA $1DFC	;/find other SFX values so you can customize it
	RTL

Glitter:
	LDA $7F                   
        ORA $81                   
        BNE ReturnLoop
        LDY #$03	;Find free sprite effect slot

LoopStart:
        LDA $17C0,y
        BEQ CGlitter	;Branch if one found
        DEY
        BPL LoopStart

ReturnLoop:
	RTS			

CGlitter:	
	LDA #$05                
        STA $17C0,y             
        LDA $9A                   
        AND #$F0                
        STA $17C8,y             
        LDA $98                   
        AND #$F0                
        STA $17C4,y             
        LDA $1933               
        BEQ Addr           
        LDA $9A                   
        SEC                       
        SBC $26                   
        AND #$F0                
        STA $17C8,y             
        LDA $98                   
        SEC                       
        SBC $28                   
        AND #$F0                
        STA $17C4,y  
           
Addr:
        LDA #$10                
        STA $17CC,y             
	RTS                      

SFX:
	LDA #$29	;\Play "correct" SFX. Go http://smwc.me/t/6665 to
	STA $1DFC	;/find other SFX values so you can customize it

;	INC $14AF	;Uncomment this if you want the ON/OFF switch to turn off (see readme for details)

Return:
	RTL



Again, this isn't my code, this is for the Coinhunt Pack, in order to create a "collectible coin" effect, I added %set_item_memory() and then inserted an object in ObjecTool. Moving %set_item_memory() to different locations didn't change anything, but it only works to set the memory if it's inside the Work routine (probably pretty obvious). The object insert code is:

Code
CustObj20:
	;Red Coin tile 1570, uses item memory
	LDA #$70	
	STA $0C		
	LDA #$15	
	STA $0D		
	LDX #$02	
	JMP SingleBlockObjects


And nowhere in the set_item_memory routine (in GPS/routines/set_item_memory.asm) do I see any hints as to what value is misplaced (either in the routine itself or in the block) for it to act like the offending question block (extended object 35).

Video of the behavior. When Mario hits from below it acts like a question block and still collects a coin (as seen in the counter). When Mario hits it from another direction it is briefly solid and then collects a coin and disappears. In Map16, the "Act As" is set to 25 - the displayed coins are inserted as Custom Objects but the behavior is the same with using the tile from Map16 as well.


Thoughts on this one?

Update: messing with the Act As changes the behavior. The closest I could get it to pass-thru was to set the Act As to B (climbing net tile) - which Mario still gets stopped for a split second when landing on top but no longer treats it as a question block. Everything else either spawns a question block (like Act As 25) or makes it solid all around before collected... I'm sure this is something I messed up somewhere >_<
The idea is that within blocks, Y is used as the acts like high byte i.e. the page number (in contrast to the low byte which has dedicated memory) and set_item_memory is a routine which uses it, often resulting in some acts like value which will cause the block to act like it's from page 1 (hence why it's often the ?-block with the balloon/key/wings as the block goes from 25 to 125). Just move the PLY a couple lines downwards so that Y is kept as it is even after calling the routine.
That makes a lot of sense, thank you.