Good way to start a script for all players?

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
Snocks
New User
Posts: 19
Joined: Sat Mar 07, 2009 8:36 am

Good way to start a script for all players?

Post by Snocks » Sun Mar 22, 2009 6:18 am

Hey

Im looking for a way to start a script for all players. I using pol 095 and I tried a way I thought would work.

Code: Select all

    local players := EnumerateOnlineCharacters();
    local numplayer := len(players);
    local player;

    local i := 0;

for (i := 1; i <= numplayer; i := i + 1)
	player := players[i];
    
    If (player.cmdlevel==0)

	start_script( "::XXX", player );
    endif
endfor
Wouldn't this code start the script on the first player, then move to the next one before that script finish? Cus right now it runs the script in the first player, but then it stops.

mr bubbles
Grandmaster Poster
Posts: 120
Joined: Thu Jan 18, 2007 2:34 am

Re: Good way to start a script for all players?

Post by mr bubbles » Sun Mar 22, 2009 6:35 am

Yep that will start the script for each player. I see no problem with it.

Snocks
New User
Posts: 19
Joined: Sat Mar 07, 2009 8:36 am

Re: Good way to start a script for all players?

Post by Snocks » Sun Mar 22, 2009 6:38 am

mr bubbles wrote:Yep that will start the script for each player. I see no problem with it.
Will it wait for the script to finish? Because when I test it the script starts for just the first player.

User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

Re: Good way to start a script for all players?

Post by ncrsn » Sun Mar 22, 2009 6:53 am

You may want to test another way to accomplish that. Basically it's the same but without all those neat variables. Documentation will tell you more about foreach statement if it's a new one to you.

Code: Select all

foreach player in EnumerateOnlineCharacters()
    if (player.cmdlevel == 0)
         Start_Script("::XXX", player);
    endif
endforeach
Also, using print function will help you to debug your scripts. E.g. adding print(i); inside the for loop would tell you for sure how many times the new script was launched.

Snocks
New User
Posts: 19
Joined: Sat Mar 07, 2009 8:36 am

Re: Good way to start a script for all players?

Post by Snocks » Sun Mar 22, 2009 7:05 am

ncrsn wrote:You may want to test another way to accomplish that. Basically it's the same but without all those neat variables. Documentation will tell you more about foreach statement if it's a new one to you.

Code: Select all

foreach player in EnumerateOnlineCharacters()
    if (player.cmdlevel == 0)
         Start_Script("::XXX", player);
    endif
endforeach
Also, using print function will help you to debug your scripts. E.g. adding print(i); inside the for loop would tell you for sure how many times the new script was launched.

Yeah, ill try that way :) Thanks, ill get back if it works :)

mr bubbles
Grandmaster Poster
Posts: 120
Joined: Thu Jan 18, 2007 2:34 am

Re: Good way to start a script for all players?

Post by mr bubbles » Sun Mar 22, 2009 7:19 am

start_script doesn't wait for the script to finish, it just starts it then moves on.

Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am
Location: Livorno, Italy
Contact:

Re: Good way to start a script for all players?

Post by Gnafu » Mon Mar 23, 2009 2:16 am

Do you have any setcritical() in your "::XXX" script?

Post Reply