|
while loops inside of an action
#368249
04/23/11 12:25
04/23/11 12:25
|
Joined: Mar 2003
Posts: 3,010 analysis paralysis
NITRO777
OP
Expert
|
OP
Expert
Joined: Mar 2003
Posts: 3,010
analysis paralysis
|
function player_scanning()
{
while (1)
{
c_scan(my.x, my.pan, vector(360, 0, 500), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);
if (you)
{
ent_create ("slider.pcx", vector (you.x, you.y, you.z + 60), entity_marker);
}
wait (1);
}
}
action my_enemy() // attach this action to your enemies
{
player_scanning();
var idle_percentage = 0;
var run_percentage = 0;
var death_percentage = 0;
var content_right[3]; // tracks the content in front of the player
var content_left[3]; // tracks the content in front of the player
var temp[3];
set(my,POLYGON);// use accurate collision detection
my.health = 100;
my.emask |= ENABLE_IMPACT; // the enemy is sensitive to impact with player's bullets
my.event = got_shot; // and runs this function when it is hit
my.status = idle; // that's the same thing with my.skill1 = 1; (really!)
while (my.status != dead) // this loop will run for as long as my.skill1 isn't equal to 3
{
Hi, IN this code notice that I call the player_scanning() function from within the player's action and it has a while(1) loop. However if I did NOT call that function, and instead simply placed that while loop at the beginning of my player action, then the player's next while (my.status != dead) would never activate. So can someone tell me the mechanics behind why this is? Why does this while loop work outside in a function, but not inside the action, like when and how does the engine run these? Any insight you might be able to give me is appreciated Thanks
|
|
|
Re: while loops inside of an action
[Re: 3run]
#368252
04/23/11 12:41
04/23/11 12:41
|
Joined: Mar 2003
Posts: 3,010 analysis paralysis
NITRO777
OP
Expert
|
OP
Expert
Joined: Mar 2003
Posts: 3,010
analysis paralysis
|
It DOES work fine! I know that. Im wondering WHY it works I am curious how the engine operates, why I cant run the while(1) loop directly within the action yet I can in the outside function... EDIT: I guess the official term for it is program flow I am wondering in which order the engine will run these loops....
Last edited by NITRO777; 04/23/11 12:42.
|
|
|
Re: while loops inside of an action
[Re: MasterQ32]
#368256
04/23/11 13:04
04/23/11 13:04
|
Joined: Mar 2003
Posts: 3,010 analysis paralysis
NITRO777
OP
Expert
|
OP
Expert
Joined: Mar 2003
Posts: 3,010
analysis paralysis
|
Ok thanks. SO that might allow me to do some interesting things. So for example if I have within my action:
action example() { while1_function001(); while1_function002(); while1_function003(); etc...
So if I understand you right they run their while loop 1 time before the wait instruction then go to the next function in sequential order? And the my pointer could be used in each one?
Last edited by NITRO777; 04/23/11 13:06.
|
|
|
|