UpdateCageKeyDoorsScript::
	writebyte 0
	pushvar
.loop
	pullvar
	scall GetCageKeyDoorArrayPointer
	sif true
		cmdwitharrayargs
		db changeblock_command, %111, 2, 3, 4
		endcmdwitharrayargs
	popvar
	addvar 1
	pushvar
	comparevartobyte wCageKeyDoorsArrayLength
	if_equal 1, .loop
	popvar
	return_if_callback_else_end

HandleCageKeyDoor::
	scall GetCageKeyDoorArrayPointer
	sif true
		end
	playsound SFX_READ_TEXT_2
	opentext
	checkitem CAGE_KEY
	sif false
		jumptext .need_key_text
	writetext .want_to_unlock_text
	yesorno
	sif false, then
		closetext
		end
	sendif
	writetext .unlocked_text
	setevent -1
	takeitem CAGE_KEY, 1
	playsound SFX_ENTER_DOOR
	scall UpdateCageKeyDoorsScript
	refreshscreen 0
	reloadmappart
	closetext
	end

.need_key_text
	db TX_COMPRESSED, $72, $85, $a8, $43, $3c, $cd, $8d, $bb, $c9
	db $bc, $26, $0c, $14, $b0, $c6, $89, $d0, $b2
	db $a4, $aa, $d2, $34, $4c, $84, $2b
	db $f5, $34

.want_to_unlock_text
	db TX_COMPRESSED, $e0, $0c, $04, $16, $a5, $5a, $4b, $96
	db $17, $9a, $27, $42, $ca, $94, $b4, $8d, $13, $21, $0a, $e9
	db $69, $a0

.unlocked_text
	db TX_COMPRESSED, $73, $93, $a1, $65, $48, $f3, $2d
	db $26, $f6, $42, $15, $f1
	db $a7, $88

GetCageKeyDoorArrayPointer:
	copybytetohalfwordvar wCageKeyDoorsArrayPointer
	loadarray -1, 5
	copybytetovar wCageKeyDoorsArrayBank
	copyvartobyte wScriptArrayBank
	readarrayhalfword 0
	checkevent -1
	end
