Gungame.core.players.shortcuts.setAttribute

From GunGame5 Documentation

(Difference between revisions)
Jump to: navigation, search
Line 10: Line 10:
examples=<source lang="python"># ../<MOD>/addons/eventscripts/gungame/scripts/custom/gg_sample/gg_sample.py
examples=<source lang="python"># ../<MOD>/addons/eventscripts/gungame/scripts/custom/gg_sample/gg_sample.py
-
from gungame.core.players.shortcuts import addAttributeCallBack
 
from gungame.core.players.shortcuts import setAttribute
from gungame.core.players.shortcuts import setAttribute
 +
from gungame.core.players.shortcuts import addAttributeCallBack
 +
from gungame.core.players.shortcuts import removeAttributeCallBack
def load():
def load():

Revision as of 14:38, 27 April 2009



Function: setAttribute

Module: [[{{{module}}}]]
Class: {{{class}}}
GunGame Version: {{{ggversion}}}

Function Overview

Table of Contents

Contents


Description

{{{description}}}

Arguments

setAttribute(filter, attribute, value)
  • filter
  • attribute
    • The str() name of the attribute
  • value
    • The value of the attribute


Examples

# ../<MOD>/addons/eventscripts/gungame/scripts/custom/gg_sample/gg_sample.py
 
from gungame.core.players.shortcuts import setAttribute
from gungame.core.players.shortcuts import addAttributeCallBack
from gungame.core.players.shortcuts import removeAttributeCallBack
 
def load():
    # Set the custom attribute "myattribute" 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_sample')
 
def unload():
    '''
    When you unload the custom addon, so long as the correct "addon" argument
    was provided, "removeCallBackForAddons('addon_name_being_unloaded')" will be called,
    which in this case will be "removeCallBackForAddon('gg_sample')". Therefore, the
    following "removeAttributeCallBack('myattribute')" is not necessary, but moreso
    exists for the sake of showing how to use the function.
    '''
    # Remove the custom attribute "myattribute" from all players
    removeAttributeCallBack('myattribute')
 
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':
        # Make sure the value is from 0-10
        if value_to_be_checked in range(0, 11):
            pass
        else:
            raise ValueError('Value must be between 0 and 10!')

Notes

{{{notes}}}

See Also

{{{seealso}}}

Personal tools