Reference

AI API

The AI object NPC routines use to decide where a person goes.

AI is the person an NPC routine (AI/*.lua) is planning for. Routines also see WHEN, day_of_week, HoursElapsed, Random(a, b), isOpen(tag) and findNearby(from, { tags }).

10/10 documented

Reading

AI:building("home" | "work" | "current") → text#

A venue tag, "" if none.

AI:getUntil() → number#

The hour their current plan ends.

AI:getVar(key) → value#

One of their variables (the same ones Actor:getVar reads).

AI:isOpen(venueTag) → boolean#

Venues of that type are open now.

AI:partner() → AI#

Their spouse, else who they date, as another AI object; nil if nobody.

AI:placeExists(venueTag) → boolean#

This city has a building of that type.

AI:stat(name) → number#

A stat; "age" and "attractiveness" work even without a stat of that name.

Deciding

AI:goTo(venueTag, untilHour)#

Sends them there until that absolute hour (HoursElapsed + n). An empty tag does nothing so the next routine gets a turn.

AI:goTo(AI:building("home"), HoursElapsed + 8)
AI:random([min,] max) → number#

The routine's own seeded random: no argument, a number from 0 to 1; one, a whole number from 1 to max; two, from min to max. Counts towards the routine's 128-operation budget.

if AI:random() < 0.3 then return AI:goTo("park") end
AI:setVar(key, value)#

Sets one of their variables (_today, _thisweek, _thismonth suffixes reset automatically).