The context native AI script function returns a script context reference (@ variable) for a group. This is needed when you must pass a group reference as a parameter to a native function that accepts a c (context) type argument.
In AI script, you can already call functions on named groups directly using the dot syntax (e.g. other_group.my_function()). However, native functions that accept a group as a parameter — like queryEgs, giveReward, newNpcChildGroup, talkTo, etc. — require a @ context variable. The context() function bridges this gap by converting a group reference into a storable, passable @ variable.
(context: c)context()
CStateInstance), stored as a @ prefixed variable.| Feature | Named group (e.g. my_group) |
Context variable (e.g. @grp) |
|---|---|---|
| Call script functions | my_group.my_function(); |
@grp.my_function(); |
| Pass as native function parameter | Not possible | ()queryEgs("Hp", $eid, @grp, 4, "msg"); |
| Store in a variable | Not possible | (@grp)my_group.context(); |
| Reference current group | Use caller or parent keywords |
(@self)context(); |
The reason bare group names can't be passed as parameters is a parser limitation: in the AI script grammar, a bare name like my_group in a parameter position is parsed as a float variable read (TOKEN_NAME → PUSH_VAR_VAL), not as a group reference. The group lookup (PUSH_GROUP) is only triggered by the dot syntax (my_group.), which is a separate grammar rule for method calls and property access. Only @ prefixed names (TOKEN_CTXNAME → PUSH_CTX_VAR_VAL) produce a context type on the stack that native functions can accept.
Note that writing @my_group directly does not work as a shorthand either — @ variables are a separate namespace from group names. The @ prefix reads from the group's local context variable table (_CtxLogicVar), which is only populated by explicit assignment. Group names are resolved through findContext(), which is only called from the dot syntax grammar rule. Hence context() is the only bridge between the two.
(@myContext)context();
Call context() on a named group using the dot syntax:
(@otherGroup)npc_group_5.context();
This works for any group in the same AI instance, even if it's in a different NPC manager. The group is looked up by name across all managers.
Context references are needed for:
queryEgs, talkTo, receiveMissionItems, giveMissionItems, and giveReward trigger user events on the specified group.newNpcChildGroup returns a context for the newly created group.(@grp)other_group.context(); @grp.my_function();// Pass current group as callback target for EGS query
(@myGroup)context();
()queryEgs("Hp", $playerEid, @myGroup, 4, "hp_query");
// Get context for a group in another manager
(@bossGroup)boss_guards.context();
()giveReward("Reward!", "Rare!", "Full!", "No pts!", @bossGroup);
// Spawn a child group and store its context
(@child)newNpcChildGroup("template_scout", "patrol_machine", $zone);
// Can now call functions on the child: @child.my_function();
@ prefix for context variables and the caller/parent keywordsSource: ryzom/server/src/ai_service/nf_static.cpp (context__c), ryzom/server/src/ai_service/state_instance.cpp (findContext)