Death usecode
Posted: Thu Sep 06, 2018 1:36 pm
So, as reported in the other thread about Glimmerscape I seem to be encountering some issues with death in my mod. I'm rather stumped about what I can do to fix this, though I have some suspicions as to the cause (in a high level sense).
When the Avatar dies, nearly every time it almost seems like some other "mode" of the game is getting stuck? I don't really know how to best describe it. The biggest thing that shows something is wrong is that hot keys don't work. I also noticed if I try and bring up Exult Studio (Ctrl-Alt-M) and double click the Avatar, it brings up the save/load screen rather than the Avatar's properties.
The movement of the Avatar becomes somewhat strange as well, where if you use right click to move before death you have a "free" movement where you can adjust the Avatar's direction but after death the Avatar has to walk someone to the selected destination before you can change the direction. It's a bit hard to explain so I hope that makes sense.
I'm not sure why this would be occurring. As a test I gutted my entire death usecode down to its most basic form to try to eliminate as much of my code as possible:
void Avatar_Death object#(0x400)()
{
UI_move_object(PARTY, [1745, 1975, 0], TRUE);
var max_health = UI_get_npc_prop(AVATAR, STRENGTH);
var current_health = UI_get_npc_prop(AVATAR, HEALTH);
UI_set_npc_prop(AVATAR, HEALTH, max_health-current_health-1);
UI_clear_item_flag(AVATAR, ASLEEP);
}
This issue also seems to cause issues with saved games that were initiated with the original usecode but subsequently replaced. If you save the game and either Journey Onward or restart, you get a Microsoft Visual C++ Runtime Library error:
Assertion failed!
Program C:\Program Files (x86)\Exult\Exult.exe
File gamemap.h
Line: 130
Expression: (cx >= 0) && (cx = 0) && (cy < c_num_chunks)
When trying to recreate this if I update the usecode on one of the erroring versions of death from my original base code on death, to the testing code (as outlined above) the issue doesn't seem to arise, which to me points to something in my "normal" death code but this only happens if you start an entirely new game with the new usecode. If I replace the normal death usecode after a death with my testing death usecode and a death has already the issue arises. It seems like my code is allowing me "one free death" before it bugs out and it starts on the second death. The first death black fade in/fade out is actually different on the first death, and doesn't appear on subsequent deaths either (same code), which further leads me to believe I'm doing something that the engine doesn't like.
I do use static variables in my regular death usecode which is what I think may be the root cause somehow. This is used in scripting blocks so I can move the Avatar since I never managed to pass variables to function calls within a script block, so I function that includes a move object such as:
UI_move_object(PARTY, [avatar_dead_x, avatar_dead_y, avatar_dead_z], TRUE);
where avatar_dead_x, avatar_dead_u and avatar_dead_z are static variables I set based on where the Avatar should appear after dying, based on where the Avatar died, for example:
avatar_dead_x = 1749;
avatar_dead_y = 1957;
avatar_dead_z = 0;
which I declare in my base usecode file
static var avatar_dead_x;
static var avatar_dead_y;
static var avatar_dead_z;
Sorry for the long winded post, but if anyone has any thoughts as to what could possibly be causing this it would be appreciated. The full code of the death usecode is in my mod source in avatar_death.uc if anyone has thoughts or is interested in taking a look.
Thanks, as usual!
When the Avatar dies, nearly every time it almost seems like some other "mode" of the game is getting stuck? I don't really know how to best describe it. The biggest thing that shows something is wrong is that hot keys don't work. I also noticed if I try and bring up Exult Studio (Ctrl-Alt-M) and double click the Avatar, it brings up the save/load screen rather than the Avatar's properties.
The movement of the Avatar becomes somewhat strange as well, where if you use right click to move before death you have a "free" movement where you can adjust the Avatar's direction but after death the Avatar has to walk someone to the selected destination before you can change the direction. It's a bit hard to explain so I hope that makes sense.
I'm not sure why this would be occurring. As a test I gutted my entire death usecode down to its most basic form to try to eliminate as much of my code as possible:
void Avatar_Death object#(0x400)()
{
UI_move_object(PARTY, [1745, 1975, 0], TRUE);
var max_health = UI_get_npc_prop(AVATAR, STRENGTH);
var current_health = UI_get_npc_prop(AVATAR, HEALTH);
UI_set_npc_prop(AVATAR, HEALTH, max_health-current_health-1);
UI_clear_item_flag(AVATAR, ASLEEP);
}
This issue also seems to cause issues with saved games that were initiated with the original usecode but subsequently replaced. If you save the game and either Journey Onward or restart, you get a Microsoft Visual C++ Runtime Library error:
Assertion failed!
Program C:\Program Files (x86)\Exult\Exult.exe
File gamemap.h
Line: 130
Expression: (cx >= 0) && (cx = 0) && (cy < c_num_chunks)
When trying to recreate this if I update the usecode on one of the erroring versions of death from my original base code on death, to the testing code (as outlined above) the issue doesn't seem to arise, which to me points to something in my "normal" death code but this only happens if you start an entirely new game with the new usecode. If I replace the normal death usecode after a death with my testing death usecode and a death has already the issue arises. It seems like my code is allowing me "one free death" before it bugs out and it starts on the second death. The first death black fade in/fade out is actually different on the first death, and doesn't appear on subsequent deaths either (same code), which further leads me to believe I'm doing something that the engine doesn't like.
I do use static variables in my regular death usecode which is what I think may be the root cause somehow. This is used in scripting blocks so I can move the Avatar since I never managed to pass variables to function calls within a script block, so I function that includes a move object such as:
UI_move_object(PARTY, [avatar_dead_x, avatar_dead_y, avatar_dead_z], TRUE);
where avatar_dead_x, avatar_dead_u and avatar_dead_z are static variables I set based on where the Avatar should appear after dying, based on where the Avatar died, for example:
avatar_dead_x = 1749;
avatar_dead_y = 1957;
avatar_dead_z = 0;
which I declare in my base usecode file
static var avatar_dead_x;
static var avatar_dead_y;
static var avatar_dead_z;
Sorry for the long winded post, but if anyone has any thoughts as to what could possibly be causing this it would be appreciated. The full code of the death usecode is in my mod source in avatar_death.uc if anyone has thoughts or is interested in taking a look.
Thanks, as usual!