It is currently Tue Dec 02, 2008 5:55 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Wait_For_Event(0);
PostPosted: Wed Sep 12, 2007 8:33 pm 
Offline
User avatar

Joined: Fri Feb 10, 2006 8:08 am
Posts: 330
Location: Myrtle Beach, South Carolina
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.

Good idea?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 11:12 pm 
Offline
Certified POL Expert
User avatar

Joined: Sat Feb 04, 2006 6:26 pm
Posts: 580
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 13, 2007 12:55 am 
Offline
User avatar

Joined: Fri Feb 10, 2006 12:15 am
Posts: 225
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 13, 2007 1:50 am 
Offline
Certified POL Expert
User avatar

Joined: Sat Feb 04, 2006 5:49 pm
Posts: 798
Location: Chicago, IL USA
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 13, 2007 2:05 am 
Offline
User avatar

Joined: Fri Feb 10, 2006 8:08 am
Posts: 330
Location: Myrtle Beach, South Carolina
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 13, 2007 2:37 am 
Offline
User avatar

Joined: Fri Feb 10, 2006 12:15 am
Posts: 225
MontuZ wrote:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 13, 2007 4:17 am 
Offline
POL Developer
User avatar

Joined: Wed Jan 25, 2006 2:30 am
Posts: 430
Location: San Diego, California
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.

_________________
-Austin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 6:56 am 
Offline

Joined: Sat Feb 04, 2006 10:13 am
Posts: 12
Location: Livorno Italy
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....

_________________
-----------------------------------------
Zandor
Scripter ZHI Shard


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl