Page 1 of 1

bots istances aren't processed properly at startup

Posted: Wed Jul 20, 2016 8:50 pm
by JakSparro98
When I use a startup trigger to load a script to count both users and bots only the players instances are loaded into the array but if i run the method by a timer with 0 seconds of delay it works.

The code is this:

Code: Select all

public void EntityCounter(TriggerArgs args){

IPlayer[] entities=Game.GetPlayers();
int i=0;

foreach (IPlayer count in entities){
i++;
}
Game.ShowPopupMessage(""+i);
}
The map for testing the issue:
http://download1076.mediafire.com/ezq9t ... 3/bug.sfdm

I don't know if this is a bug but surely the bots istances are loaded after the first game clock cycle is run.

Re: bots istances aren't processed properly at startup

Posted: Wed Jul 20, 2016 9:28 pm
by gwendalaze
if I remember well, startup trigger take acion before OnStartup method
Anyway, you should put a link the map you used to test this for the devs to understand where the bug is coming from

Re: bots istances aren't processed properly at startup

Posted: Wed Jul 20, 2016 10:20 pm
by JakSparro98
gwendalaze wrote:if I remember well, startup trigger take acion before OnStartup method
Anyway, you should put a link the map you used to test this for the devs to understand where the bug is coming from
Thanks for the reply, I've tried your advice but nothing changed, now I also posted the map. I didn't do it before because it's an empty map, I rewrited code more times before open this topic but it seems a problem of the first moments of the map initialization.

Re: bots istances aren't processed properly at startup

Posted: Wed Jul 20, 2016 10:55 pm
by Gurt
You're assuming that the game should be smart enough to figure out the priority order for all your "Activate on startup" triggers. This is not the case. The OnStartup will run before any triggers are activated. All "Activate on startup" triggers runs in a non-defined order (depending on how the map is edited, how/when you create the tiles etc...). Maybe you want 3 out of 6 bots to spawn before your script runs, or after, or before. You need to defined the order of events to accomplish what you're trying to do.

To define the order simply set false to the "run on startup" property to all triggers. Now they won't trigger so we need to do it. You could let one well defined "StartupTrigger" be your starting point and let it point on the first PlayerSpawnTrigger. Let that one in turn activate the second PlayerSpawnTrigger. Let that one in turn activate the third PlayerSpawnTrigger and so on... let the last PlayerSpawnTrigger call the script you want to run.

Or use a delay timer.

We have plans to add other events in the future to the ScriptAPI to simplify certain thinks like "AfterStartup" and "OnPlayerCreated" to simplify things.

Re: bots istances aren't processed properly at startup

Posted: Thu Jul 21, 2016 12:18 am
by JakSparro98
Gurt wrote:You're assuming that the game should be smart enough to figure out the priority order for all your "Activate on startup" triggers. This is not the case. The OnStartup will run before any triggers are activated. All "Activate on startup" triggers runs in a non-defined order (depending on how the map is edited, how/when you create the tiles etc...). Maybe you want 3 out of 6 bots to spawn before your script runs, or after, or before. You need to defined the order of events to accomplish what you're trying to do.

I see, for some reason I thought that the properties added in the editor before the simulation was stored as actions to process during the loading of the map itself so all was before the first clock of the map.

I even studied process concurrency and semaphores at school... :oops: