Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

Decaying blackboard events


When we update our agent senses, we can use the deltaTimeInMillis to decrement the time-to-live value of each stored event. If the time-to-live drops below 0, we'll remove the stored event:

AgentSenses.lua:

local function PruneEvents(events, deltaTimeInMillis)
    local validEvents = {};
    
    for index = 1, #events do
        local event = events[index];
        event.ttl = event.ttl - deltaTimeInMillis;
        
        if (event.ttl > 0) then
            table.insert(validEvents, event);
        end
    end
    
    return validEvents;
end

Providing a helper function to wrap pruning events is useful, as most auditory events will require being pruned during the normal agent's update loop:

AgentSenses.lua:

local function PruneBlackboardEvents(
    blackboard, attribute, deltaTimeInMillis)
    
    local attributeValue = blackboard:Get(attribute);
    
    if (attributeValue) then
        blackboard:Set(
            attribute,
            PruneEvents(attributeValue...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)