PyArianneAPIDefinition: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
imported>StephenIerodiaconou No edit summary |
||
| (15 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
=pyarianne API= |
=pyarianne API= |
||
pyarianne is the API that connects your game to the Arianne system. |
pyarianne is the API that connects your game to the Arianne system. For an example of how to use this API, please just go to the [[pyArianneAPIExample]] page. |
||
It is composed of several functions that provide you with |
It is composed of several functions that provide you with basic, low level access in to the Arianne framework. |
||
It is important that you respect the order of the functions; if not the behaviour of your application will be irratic. |
It is important that you respect the order of the functions; if not the behaviour of your application will be irratic. |
||
| Line 7: | Line 8: | ||
Let's first have a look at the function calls and we will describe the data structures later. |
Let's first have a look at the function calls and we will describe the data structures later. |
||
''setIdleMethod(function)'' <br> |
* ''setIdleMethod(function)'' <br> |
||
This function sets the callback function that will be called each time the module needs to block for a given period of time. The callback function should return true to make the pyarianne module continue wait for data, and false will make the modile stop waiting. |
This function sets the callback function that will be called each time the module needs to block for a given period of time. The callback function should return true to make the pyarianne module continue wait for data, and false will make the modile stop waiting. |
||
<pre> |
<pre> |
||
| Line 16: | Line 17: | ||
</pre> |
</pre> |
||
''connectToArianne(serverName, port)'' <br> |
* ''connectToArianne(serverName, port)'' <br> |
||
This function is called to connect to an Arianne server running on the server whose name (DNS) or IP is <serverName> and that can be reached at port <port>. |
This function is called to connect to an Arianne server running on the server whose name (DNS) or IP is <serverName> and that can be reached at port <port>. |
||
This function will never fail. |
This function will never fail. |
||
| Line 24: | Line 25: | ||
</pre> |
</pre> |
||
''login(username, password)'' <br> |
* ''login(username, password)'' <br> |
||
This function should be called AFTER connecting to the Arianne server; it tries to login to the server using the given username and password combination. |
This function should be called AFTER connecting to the Arianne server; it tries to login to the server using the given username and password combination. |
||
It will return true if the login is completed successfully or false if there is a problem and it then will set error to true. |
It will return true if the login is completed successfully or false if there is a problem and it then will set error to true. |
||
| Line 35: | Line 36: | ||
</pre> |
</pre> |
||
''availableCharacters()'' <br> |
* ''availableCharacters()'' <br> |
||
Once you have logged into Arianne, you can get the list of characters available for your account. |
Once you have logged into Arianne, you can get the list of characters available for your account. |
||
It will return a list of name of characters. |
It will return a list of name of characters. |
||
| Line 42: | Line 43: | ||
</pre> |
</pre> |
||
''serverInfo()''<br> |
* ''serverInfo()''<br> |
||
Once you have logged into Arianne, you can get the list of server properties that may be relevant to the client. |
Once you have logged into Arianne, you can get the list of server properties that may be relevant to the client. |
||
It will return a list of properties of the form attribute=value. |
It will return a list of properties of the form attribute=value. |
||
| Line 49: | Line 50: | ||
</pre> |
</pre> |
||
''getGameType()''<br> |
* ''getGameType()''<br> |
||
Returns a string containing the type of game we are playing. |
Returns a string containing the type of game we are playing. |
||
<pre> |
<pre> |
||
| Line 56: | Line 57: | ||
</pre> |
</pre> |
||
''chooseCharacter(character)''<br> |
* ''chooseCharacter(character)''<br> |
||
Once have recieved the list of characters you can choose one of them that you will use to enter the game. |
Once have recieved the list of characters you can choose one of them that you will use to enter the game. |
||
If it enters correctly it will return true, otherwise it will return false. |
If it enters correctly it will return true, otherwise it will return false. |
||
| Line 67: | Line 68: | ||
</pre> |
</pre> |
||
''hasRPMap()''<br> |
* ''hasRPMap()''<br> |
||
This function returns true if there is a Map available for this game. |
This function returns true if there is a Map available for this game. |
||
''getRPMap()''<br> |
* ''getRPMap()''<br> |
||
This functions returns a list of objects containing the data of the Map. |
This functions returns a list of objects containing the data of the Map. |
||
It is up to your client to process it and build an appropriate representation. |
It is up to your client to process it and build an appropriate representation. |
||
| Line 76: | Line 77: | ||
</pre> |
</pre> |
||
''hasPerception()''<br> |
* ''hasPerception()''<br> |
||
This function returns true if there is a perception available for your game. |
This function returns true if there is a perception available for your game. |
||
''getPerception()''<br> |
* ''getPerception()''<br> |
||
This function returns a perception that should have been previously stored by a call to hasPerception, using a polling technique. This function won't block the client. |
This function returns a perception that should have been previously stored by a call to hasPerception, using a polling technique. This function won't block the client. |
||
<pre> |
<pre> |
||
| Line 86: | Line 87: | ||
</pre> |
</pre> |
||
''send(action)''<br> |
* ''send(action)''<br> |
||
''sendBlocking(action)''<br> |
* ''sendBlocking(action)''<br> |
||
Both these functions send an Action the server, but the blocking function will block until the server replies with a Action ACK message, which will be around the length of the trip time of the message. |
Both these functions send an Action the server, but the blocking function will block until the server replies with a Action ACK message, which will be around the length of the trip time of the message. |
||
They return nothing. |
They return nothing. |
||
| Line 98: | Line 99: | ||
</pre> |
</pre> |
||
''logout()''<br> |
* ''logout()''<br> |
||
Exits the Arianne enviroment and returns true. |
Exits the Arianne enviroment and returns true. |
||
If it returns false it means the logout didn't happened. |
If it returns false it means the logout didn't happened. |
||
| Line 106: | Line 107: | ||
</pre> |
</pre> |
||
''iserror()''<br> |
* ''iserror()''<br> |
||
Return true if there is a significant error |
Return true if there is a significant error |
||
''errorReason()''<br> |
* ''errorReason()''<br> |
||
Returns a string containing an explanation of the error. |
Returns a string containing an explanation of the error. |
||
| Line 125: | Line 126: | ||
It has several methods: |
It has several methods: |
||
''has(attribute)''<br> |
* ''has(attribute)''<br> |
||
Returns true if the action has the attibute whose name matches attribute. |
Returns true if the action has the attibute whose name matches attribute. |
||
''put(attribute, value)''<br> |
* ''put(attribute, value)''<br> |
||
Sets an attribute in the action where attribute's name is attribute and value is value. Value can either be a string or a number. |
Sets an attribute in the action where attribute's name is attribute and value is value. Value can either be a string or a number. |
||
''get(attribute)''<br> |
* ''get(attribute)''<br> |
||
Returns a string containing the value of the attribute |
Returns a string containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
''getInt(attribute)''<br> |
* ''getInt(attribute)''<br> |
||
Returns an integer containing the value of the attribute |
Returns an integer containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
''remove(attribute)''<br> |
* ''remove(attribute)''<br> |
||
Removes an attribute from the action or fails if it doesn't exist. |
Removes an attribute from the action or fails if it doesn't exist. |
||
''clear()''<br> |
* ''clear()''<br> |
||
Remove all the attributes from the action |
Remove all the attributes from the action |
||
''equals(action)''<br> |
* ''equals(action)''<br> |
||
Return true if the action is equal to this action. |
Return true if the action is equal to this action. |
||
''toString()''<br> |
* ''toString()''<br> |
||
Return a string representation of the action |
Return a string representation of the action |
||
''size()''<br> |
* ''size()''<br> |
||
Returns the number of attributes of the action |
Returns the number of attributes of the action |
||
| Line 159: | Line 160: | ||
It has several methods: |
It has several methods: |
||
''has(attribute)''<br> |
* ''has(attribute)''<br> |
||
Returns true if the object has the attibute whose name matches attribute. |
Returns true if the object has the attibute whose name matches attribute. |
||
''put(attribute, value)''<br> |
* ''put(attribute, value)''<br> |
||
Sets an attribute in the object where attribute's name is attribute and value is value. Value can either be a string or a number. |
Sets an attribute in the object where attribute's name is attribute and value is value. Value can either be a string or a number. |
||
''get(attribute)''<br> |
* ''get(attribute)''<br> |
||
Returns a string containing the value of the attribute |
Returns a string containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
''getInt(attribute)''<br> |
* ''getInt(attribute)''<br> |
||
Returns an integer containing the value of the attribute |
Returns an integer containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
''remove(attribute)''<br> |
* ''remove(attribute)''<br> |
||
Removes an attribute from the object or fails if it doesn't exist. |
Removes an attribute from the object or fails if it doesn't exist. |
||
''clear()''<br> |
* ''clear()''<br> |
||
Removes all the attributes from the object |
Removes all the attributes from the object |
||
''equals(object)''<br> |
* ''equals(object)''<br> |
||
Returns true if the object is equals to this object. |
Returns true if the object is equals to this object. |
||
''toString()''<br> |
* ''toString()''<br> |
||
Returns a string representation of the object |
Returns a string representation of the object |
||
''size()''<br> |
* ''size()''<br> |
||
Returns the number of attributes of the object plus all the attributes of the objects that exist in the slots. |
Returns the number of attributes of the object plus all the attributes of the objects that exist in the slots. |
||
''addSlot(slot)''<br> |
* ''addSlot(slot)''<br> |
||
Add an RPSlot to the object; it will fail if the slot already exists on the object. So if you want to replace a slot, first remove the current slot. |
Add an RPSlot to the object; it will fail if the slot already exists on the object. So if you want to replace a slot, first remove the current slot. |
||
''getSlot(name)''<br> |
* ''getSlot(name)''<br> |
||
Returns an RPSlot from the Object whose name is name. |
Returns an RPSlot from the Object whose name is name. |
||
It will fail if there is no such slot. |
It will fail if there is no such slot. |
||
''removeSlot(name)''<br> |
* ''removeSlot(name)''<br> |
||
Removes the slot from the object whose name is name. |
Removes the slot from the object whose name is name. |
||
It will fail if there is no such slot. |
It will fail if there is no such slot. |
||
''hasSlot(name)''<br> |
* ''hasSlot(name)''<br> |
||
Returns true if the object has a slot named name. |
Returns true if the object has a slot named name. |
||
''applyAddedDifferences(added)''<br> |
* ''applyAddedDifferences(added)''<br> |
||
''applyDeletedDifferences(deleted)''<br> |
* ''applyDeletedDifferences(deleted)''<br> |
||
''removeAllHidden()''<br> |
* ''removeAllHidden()''<br> |
||
Don't use these methods directly. See PerceptionHandler. |
Don't use these methods directly. See PerceptionHandler. |
||
| Line 212: | Line 213: | ||
It has several methods: |
It has several methods: |
||
''name''<br> |
* ''name''<br> |
||
It contains the name of the Slot. It is a string. |
It contains the name of the Slot. It is a string. |
||
''add(object)''<br> |
* ''add(object)''<br> |
||
This method adds an object to the slot or replaces it if it exists. |
This method adds an object to the slot or replaces it if it exists. |
||
''get(id)''<br> |
* ''get(id)''<br> |
||
Returns the object whose id is id or fails if there is no such object. |
Returns the object whose id is id or fails if there is no such object. |
||
''getByPosition(i)''<br> |
* ''getByPosition(i)''<br> |
||
Returns the object whose position on the list of objects is i or fails if there is no such position |
Returns the object whose position on the list of objects is i or fails if there is no such position |
||
''has(id)''<br> |
* ''has(id)''<br> |
||
Returns true if there is an object whose id is id. False otherwise |
Returns true if there is an object whose id is id. False otherwise |
||
''remove(id)''<br> |
* ''remove(id)''<br> |
||
Removes the object whose id is id or fails if it can't be found- |
Removes the object whose id is id or fails if it can't be found- |
||
''clear()''<br> |
* ''clear()''<br> |
||
Removes all the objects in the slot. |
Removes all the objects in the slot. |
||
''equals(slot)''<br> |
* ''equals(slot)''<br> |
||
Return true if the slot is equals to this slot. |
Return true if the slot is equals to this slot. |
||
''toString()''<br> |
* ''toString()''<br> |
||
Return a string representation of the slot |
Return a string representation of the slot |
||
''size()''<br> |
* ''size()''<br> |
||
Returns the number of objects in the slot. |
Returns the number of objects in the slot. |
||
| Line 249: | Line 250: | ||
Of course you can and must ignore such lowlevel details when using pyarianne.<br> |
Of course you can and must ignore such lowlevel details when using pyarianne.<br> |
||
It contains: <br> |
It contains: <br> |
||
''type''<br> |
* ''type''<br> |
||
It is an enum type that can be either 0 or 1 to indicate SYNC and DELTA perception type. |
It is an enum type that can be either 0 or 1 to indicate SYNC and DELTA perception type. |
||
''timestamp''<br> |
* ''timestamp''<br> |
||
It is a constant incremental counter to mark each perception |
It is a constant incremental counter to mark each perception |
||
''added''<br> |
* ''added''<br> |
||
''modifiedAdded''<br> |
* ''modifiedAdded''<br> |
||
''modifiedDeleted''<br> |
* ''modifiedDeleted''<br> |
||
''deleted''<br> |
* ''deleted''<br> |
||
These are a list of RPObjects that contain added, modified added, modified deleted and deleted objects respectively |
These are a list of RPObjects that contain added, modified added, modified deleted and deleted objects respectively |
||
''myRPObjectChanged''<br> |
* ''myRPObjectChanged''<br> |
||
It is a boolean value that will be true if myRPObject contains a valid value |
It is a boolean value that will be true if myRPObject contains a valid value |
||
''myRPObject''<br> |
* ''myRPObject''<br> |
||
It is our RPObject containing all the hidden attributes. |
It is our RPObject containing all the hidden attributes. |
||
| Line 273: | Line 274: | ||
For a unknown reason if this structure is written in Python it is not understood by SWIG and objects are freed :( |
For a unknown reason if this structure is written in Python it is not understood by SWIG and objects are freed :( |
||
''objects_ |
* ''objects_ <br> |
||
It is a dict of integer<-->RPObject |
It is a dict of integer<-->RPObject |
||
| Line 281: | Line 282: | ||
The class is very simple, it has a constructor a method to handle the perception and modify the world. |
The class is very simple, it has a constructor a method to handle the perception and modify the world. |
||
''PerceptionHandler(listener)''<br> |
* ''PerceptionHandler(listener)''<br> |
||
It is passed an instance of a subclass of ~PerceptionListener that handles everything related to the perception on a detailed way. You can choose to implement your own, or use the default one. |
It is passed an instance of a subclass of ~PerceptionListener that handles everything related to the perception on a detailed way. You can choose to implement your own, or use the default one. |
||
''apply(perception, world)''<br> |
* ''apply(perception, world)''<br> |
||
Just call this method with the perception you get from getPerception and the world where objects are stored, and voila... perception gets applied. |
Just call this method with the perception you get from getPerception and the world where objects are stored, and voila... perception gets applied. |
||
''PerceptionListener''<br> |
* ''PerceptionListener''<br> |
||
It is a listener class for handling perceptions. |
It is a listener class for handling perceptions. |
||
Each method is called on the given event, you can execute whatever you want inside. |
Each method is called on the given event, you can execute whatever you want inside. |
||
''onAdded(object)''<br> |
* ''onAdded(object)''<br> |
||
It is called when an object is added to the world. |
It is called when an object is added to the world. |
||
''onBeforeModifiedAdded(object, previous)''<br> |
* ''onBeforeModifiedAdded(object, previous)''<br> |
||
It is called when an object is modified by adding slots or attributes. |
It is called when an object is modified by adding slots or attributes. |
||
''onBeforeModifiedDeleted(object, previous)''<br> |
* ''onBeforeModifiedDeleted(object, previous)''<br> |
||
It is called when an object is modified by removing slots or attributes. |
It is called when an object is modified by removing slots or attributes. |
||
''onModifiedAdded(object)''<br> |
* ''onModifiedAdded(object)''<br> |
||
It is called when an object has been modified by adding slots or attributes. |
It is called when an object has been modified by adding slots or attributes. |
||
''onModifiedDeleted(object)''<br> |
* ''onModifiedDeleted(object)''<br> |
||
It is called when an object has been modified by removing slots or attributes. |
It is called when an object has been modified by removing slots or attributes. |
||
''onDeleted(object)''<br> |
* ''onDeleted(object)''<br> |
||
It is called when an object is deleted of the world |
It is called when an object is deleted of the world |
||
''onMyRPObject(changed, object)''<br> |
* ''onMyRPObject(changed, object)''<br> |
||
It is called on each perception, if changed is true, object contains the resulting new object for our character, else it will contains None |
It is called on each perception, if changed is true, object contains the resulting new object for our character, else it will contains None |
||
''onPerception()''<br> |
* ''onPerception()''<br> |
||
It is called on each perception. |
It is called on each perception. |
||
''onClear()''<br> |
* ''onClear()''<br> |
||
It is called each time the whole world is emptied |
It is called each time the whole world is emptied |
||
''onUnsync()''<br> |
* ''onUnsync()''<br> |
||
When you get out of sync this method is called |
When you get out of sync this method is called |
||
''onSync()''<br> |
* ''onSync()''<br> |
||
When you recover sync with server this method is called |
When you recover sync with server this method is called |
||