Joined: 10 Feb 2006 Posts: 298 Location: Myrtle Beach, South Carolina
Posted: Thu Sep 13, 2007 12:33 am Post subject: Wait_For_Event(0);
Get_Queued_Event(); - Would just return the most recent queued event.
Get_Events_Queued(); - Would return an array of queued events.
I'd like to have these for NPCs. For instance; when you have an npc chase after a mobile, that npc is only going to run after the player, unless you put in a wait for event for 1 second(I tried 0 and nothing happens), then every loop that npc will stop for 1 second, which makes for a very slow and easy to kill npc.
What some of my players are doing is sending out one player to have the npc chase them, while another player sits and attacks/kills the npc.
I'm not using the latest version of POL, but when I convert(which might be never, lol because of how incredibly stable we are atm.) It would be nice to have those options to make better AI.
Whenever I've see the message on the console about npc event queues being full, and events being discarded, I've wanted more tools to deal with the situation. Events trigger events in bewildering cascades of confusion at times and to be able to test and list the event queue would be extremely handy for debugging.
So for entirely different reasons, having Get_Events_Queued(); would be most welcome.
I just tested using 097 RC5 core, Wait_For_Event(0); returned event from queue.
Using that information, scripting function Get_Events_Queued() is possible.
Code:
function Get_Events_Queued( )
// Result will be array of structs.
var result := array;
var ev;
while (ev := Wait_For_Event(0))
result.Append(ev);
endwhile
return result;
endfunction
That's pseudocode, but I think the idea will do.
Author
Message
CWO
Joined: 04 Feb 2006 Posts: 713 Location: Chicago, IL USA
Posted: Thu Sep 13, 2007 5:50 am Post subject:
Works on 096.4 which I use for my shard. Are you completely sure in your tests that there is another event in the queue? Wait_for_event(0) does absolutely nothing if theres no event in the queue. I'm sure you know that but putting 0 for WFE never failed for me.
Author
Message
MontuZ Distro Developer
Joined: 10 Feb 2006 Posts: 298 Location: Myrtle Beach, South Carolina
Posted: Thu Sep 13, 2007 6:05 am Post subject:
It wouldn't return events that are queued. We want to get the events that are sent to the script while the script is doing something and not listening for events... understand?
Code:
function Get_Events_Queued( )
// Result will be array of structs.
var result := array;
var ev;
while (ev := Wait_For_Event(0))
result.Append(ev);
endwhile
return result;
endfunction
CWO: I've tried 0 several times, but I will try again. I was probably over looking something.
We want to get the events that are sent to the script while the script is doing something and not listening for events
And that's exactly what it does.
When process gots event, POL saves it into memory. I call it queue, which is array of events sent to process. Using Wait_For_Event(x) POL will return first event from the queue, no matter when it was send. And if queue is empty, it will sleep x seconds waiting for one.
Wait_For_Event(0) checks if queue is empty, and whether or not it is, returns immediately. That's why using the function I wrote one could swap the queue from POL into the script process.
Tested it out using AI-script with enabled event SYSEVENT_SPEECH. First it slept for 10 seconds, while my character flooded various texts in game next to the npc. After 10 seconds, script called and printed out result of Get_Events_Queued(). Surprisingly every phrase I flooded while npc was sleeping printed into console.
Disclaimer: I do not really know how POL handles this stuff; what I told above is just a way I quess it works.
Author
Message
Austin POL Developer
Joined: 30 Jan 2006 Posts: 356 Location: San Diego, California
Posted: Thu Sep 13, 2007 8:17 am Post subject:
Stop using single scripts to handle AI. If you get an event you have to process it. If you do everything in the same script, some things will have to wait.
Look into the brain AI in the distro to create npcs that can perform multiple tasks.
wait_for_event(#) waits # number of seconds before continuing on
if you have 5, it will wait UP to 5 seconds for an event
0 means it just keeps looping. If there is an event, itll take it, if not, it keeps going anyways. It gives you the most recent event in the queue.
Events_Waiting() will tell you if there is any events .... waiting.
Author
Message
zandor
Joined: 04 Feb 2006 Posts: 12 Location: Livorno Italy
Posted: Mon Sep 17, 2007 10:56 am Post subject:
What about define 2 threads in single ai script?
Something like:
ai.src:
program ai_script()
..code
endprogram
events ai_scripts()
..code
endevents
I know I can always use start_script() but have all code in single src could be more readable...
THe 2 threads could share same global var defined outside program or events section....