A couple of things go wrong here.. basically, agi expects you to discard resources in the same order they were loaded.. since ego's view is loaded right at the start of logic.0, it gets complicated.
the thing to remember is that agi allocates memory on a sort-of stack.. It also has linked lists containing all the loaded objects (separate ones for view, pic, sound, logic), with pointers to the memory heap.
So the resource information is contained on the heap.. and the linked list contains information on it's whereabouts in the heap and which items are loaded.
so what you have before you shapeshift is probably:
mem = GAME->LOGIC.0->EGO_VIEW->LOGIC.ROOM->SOUND->VIEW->VIEW->NEXT
logic = LOGIC.0->LOGIC.ROOM
pic = 0 // always discarding pics hopefully
view = EGO_VIEW->VIEW->VIEW
sound = SOUND
The reason why ego view is at the start is because logic.0 always loads it for a new room. The Next is the pointer to the next position in the memory heap.
so when you load up the new view, the memory will look like this:
mem = GAME->LOGIC.0->EGO_VIEW->LOGIC.ROOM->SOUND->VIEW->VIEW->*MAN_VIEW*->NEXT
logic = LOGIC.0->LOGIC.ROOM
pic = 0 // always discarding pics hopefully
view = EGO_VIEW->VIEW->VIEW->*MAN_VIEW*
sound = SOUND
and THEN you discard the ego view.. but this is where the algorithm of the agi memory gets screwy.. When agi removes an item from the view list, it just sets the next pointer of the *PREV* item to zero... since you're removing ego_view, the first item in the list, it will remove all the others too.
view = 0
that's not all.. to remove it from memory, it just sets the "next available space" pointer to point to EGO_VIEW, so when you load a new resource, it will overwrite the old resource.. this works fine.. but if you set the next available space to ego_view, new resources will write over ALL the other resources loaded in memory..
so the memory looks like this now:
mem = GAME->LOGIC.0->*NEXT*->EGO_VIEW->LOGIC.ROOM->SOUND->VIEW->VIEW->MAN_VIEW
So most of the items are still in memory, but when you load up another resource, it will load over them, AND the view list is destroyed, so the interpreter won't know about any of the loaded views..
That's why you get a "view not loaded" and possibly other weird stuff happening...
This is definately needed for a tutorial, it's kinda complicated, but I hope I made sense. The main thing to remember is to discard in the same order you load.. even if it means having an ego view and a man view in memory at the same time.
- Nick