A quick introduction to AIModels
Table of Contents
Introduction to AIModelsThink of an AIModels as a little "brain" you can attach to any user and any object in your game - but more to the point, an AI can be considered as a "class" like you are used to in object-oriented programming (OOP). There are four kinds of elements in an AIModel:
User AIs and Object AIsIn ShiVa, we differentiate between two types of AIModels: Object AIs and User AIs. Both AIModels are of the same general structure and are edited with the same editor module, but serve different functions, need to be coded differently and are attached to different things.
Object AIs are attached directly to an object in the scene. They define the object behaviour, how it reacts and behaves inside your game. Object AIs are limited to the scene the (parent) object "lives" in and accepts only Universal, Custom and Object Event Handlers, but no User Handlers. When the game is played, several instances of a same Object AI can be created and attached to different objects. So two objects with the same AIModel can have different behaviors at a specific time, because they are running two different instances of the same AIModel.
User AIs on the other hand are attached in Game Editor "Properties" panel. They catch the user input, manage the game (storage, server interactions, interface, load the scenes, ...) and identify the user in multiplayer games. User AIs are not limited to scenes, but are active as long as the user is active, and accept Universal, Custom and User Handlers, but no Object Handlers.
Accessing AIModel elements from script
this Keyword"this" represents the current AI instance. To get/set any instance member, use the 'this' keyword. In User AIs, you can get the reference to the current user via:
--return the user handle to which instance is attached toIn object AIs, you can get the reference to the object the AI is attached to using:
this.getUser ( )
--return the object handle to which instance is attached toImportant: Calling this.getObject ( ) in an AI attached to a user returns nil, and calling this.getUser ( ) in an AI attached to an object returns nil too. Keep your User and Object AIs separate!
this.getObject ( )