Okay.. I'm trying to create hp bars for everyone entity in the game... well not every entity.. but you know the typical stuff.. monsters..players..
The problem is the code only seems to work if I use a global variable... and I don't understand why... here is my code:
Code:
panel* hp_bar_panel_pointer;
define hp_bar_handle,skill45;
//the following is from inside my player script
var hp_bar_x = 0;
hp_bar_panel_pointer = pan_create("window(10, 10, 50, 5, hp_bar_bmp, hp_bar_x, 0);flags = visible; size_x = 100;size_y = 5;",1);
my.hp_bar_handle = handle(hp_bar_panel_pointer);
hp_bar_x=name_ent1(hp_bar_x);
//------------------------------------------------------------
function name_ent1(hp_bar_x_)
{
hp_bar_panel_pointer = ptr_for_handle(my.hp_bar_handle);
vec_set (temp, my.x);
temp.z += 40;
if(c_trace(my.x,camera.x,ignore_me|ignore_models|ignore_passents)==0&&my.health!= 0&&my.health_total!=0)
{
vec_to_screen (temp, camera);
name1_txt.pos_x = temp.x;
name1_txt.pos_y = temp.y;
hp_bar_panel_pointer.pos_x=name1_txt.pos_x;
hp_bar_panel_pointer.pos_y=name1_txt.pos_y+10;
name1_txt.visible = on;
hp_bar_panel_pointer.visible = on;
hp_bar_x_ = 50 - int(((my.health/my.health_total)/2)*100);
return(hp_bar_x_);
}
else
{
name1_txt.visible = off;
hp_bar_panel_pointer.visible = off;
}
}
if i make hp_bar_x a global variable and don't go bother with returning from name_ent1 everything seems to work fine... but I ABSOLUTELY NEED this to work with hp_bar_x being a local variable. I even tried doing this as hp_bar_x being a skill and I still couldn't get it to work... maybe someone can see something i can't. I'm starting to think of this as a bug.
[edit]
btw this is a logic error not syntex incase i wasn't clear on that...
[/edit]