Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Code:
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: NITRO777] #368250
04/23/11 12:32
04/23/11 12:32
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
This should work. May be scan doesn't find anything.
Make sure that entity you scan for, has ENABLE_SCAN.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
It DOES work fine! I know that. Im wondering WHY it works tongue 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: 3run] #368254
04/23/11 12:44
04/23/11 12:44
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
this is because of the gamestudio engine scheduler...
gamestudio runs functions until a wait instruction and then returns
even if the function is in a while loop
so you create a function which is used by more than one action, like minimaps etc.
also this function gets the my-pointer from the action


Visit my site: www.masterq32.de
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 Offline OP
Expert
NITRO777  Offline 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.
Re: while loops inside of an action [Re: NITRO777] #368258
04/23/11 14:35
04/23/11 14:35
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
You can do so, but I wouldn't recommand that.
It is better to use less while loops, because they are sad to slow down the code.
Zapan@work even recommanded to use only one while loop, and to call all functions from within this while loop. The called functions wouldn't have any while loop then, but are repeatedly called from the one and only while loop.

This is more appropriate than your example, IMO:

function npc()
{
while(1)
{
if(condition_1)
{
function_1;
}
if(condition_2)
{
function_2;
}
...
wait(1);
}
}

function function_1()
{
...//Do things without any while loops
}

Re: while loops inside of an action [Re: Pappenheimer] #368262
04/23/11 14:54
04/23/11 14:54
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
OK I understand.Thanks a lot.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1