Gungame.core.players.shortcuts.addAttributeCallBack
From GunGame5 Documentation
Revision as of 09:46, 27 April 2009 by GunGame5WikiAdmin (Talk | contribs)
Function: addAttributeCallback(attribute, function, addon)
Module: gungame.core.players.shortcuts
Class: Player
GunGame Version: 5.1
Function Overview
Table of Contents
Contents |
Description
Adds a callback to be triggered when the declared attribute is set via __setitem__ or __setattr__ via the Player() class. If the attribute does not exist at the time of the callback declaration, no errors are raised, and the callback is created irregardless. Two arguments must be provided for the callback function. The first will return the name of the attribute, and the second will return the value that is attempting to be set for the attribute. If you raise an error during your callback, the attribute will not be set.
Arguments
- filter
- userid
- A str() filter as used by playerlib.getPlayerList()
- function
- addon
Examples
from gungame.core.players.shortcuts import addAttributeCallBack from gungame.core.players.shortcuts import setAttribute def load(): # Set the attribute on all connected players setAttribute('#all', 'myattribute', 0) # Add the attribute callback # (this will call on "callbackFunction" any time "myattribute" is set # via the __setitem__ or __setattr__ method) addAttributeCallBack('myattribute', callbackFunction, 'gg_addon_name') def callbackFunction(name_of_the_attribute, value_to_be_checked): ''' This callback function can be used for more than 1 attribute, so that you can register multiple attribute callbacks. All that you have to do is check the name of the attribute (the first argument). The second argument is the value of the attribute. If you raise an error during your callback, the attribute will not be set to the attempted value. ''' if name_of_the_attribute == 'myattribute': if value_to_be_checked > 0 and value_to_be_checked < 10: pass else: raise ValueError('Value must be between 1 and 10!')
Notes
{{{notes}}}
See Also
{{{seealso}}}