diff --git a/docs/ba_module.md b/docs/ba_module.md index 5f8aceef..ee12044e 100644 --- a/docs/ba_module.md +++ b/docs/ba_module.md @@ -547,13 +547,13 @@ is a convenient way to access this same functionality.
(killing off or transitioning out their nodes) when the last Python reference to them disappears, so you can use logic such as: -# create a flag Actor in our game activity +# create a flag Actor in our game activity self.flag = ba.Flag(position=(0, 10, 0))-# later, destroy the flag.. - # (provided nothing else is holding a reference to it) - # we could also just assign a new flag to this value. - # either way, the old flag disappears. +# later, destroy the flag.. + # (provided nothing else is holding a reference to it) + # we could also just assign a new flag to this value. + # either way, the old flag disappears. self.flag = NoneThis is in contrast to the behavior of the more low level ba.Nodes, @@ -570,11 +570,11 @@ is a convenient way to access this same functionality.
class providing a handlemessage() method. The most universally handled message type for actors is the ba.DieMessage. -# another way to kill the flag from the example above: - # we can safely call this on any type with a 'handlemessage' method - # (though its not guaranteed to always have a meaningful effect) - # in this case the Actor instance will still be around, but its exists() - # and is_alive() methods will both return False +# another way to kill the flag from the example above: + # we can safely call this on any type with a 'handlemessage' method + # (though its not guaranteed to always have a meaningful effect) + # in this case the Actor instance will still be around, but its exists() + # and is_alive() methods will both return False self.flag.handlemessage(ba.DieMessage())@@ -1102,11 +1102,11 @@ when done.Instantiate a Call; pass a callable as the first arg, followed by any number of arguments or keywords.
-# Example: wrap a method call with 1 positional and 1 keyword arg. +# Example: wrap a method call with 1 positional and 1 keyword arg. mycall = ba.Call(myobj.dostuff, argval1, namedarg=argval2)-# Now we have a single callable to run that whole mess. -# ..the same as calling myobj.dostuff(argval1, namedarg=argval2) +# Now we have a single callable to run that whole mess. +# ..the same as calling myobj.dostuff(argval1, namedarg=argval2) mycall()@@ -1335,8 +1335,8 @@ Usage: sets the context as current on entry and resets it to the previous value on exit. -# example: load a few textures into the UI context -# (for use in widgets, etc) +# example: load a few textures into the UI context +# (for use in widgets, etc) with ba.Context('ui'): tex1 = ba.gettexture('foo_tex_1') tex2 = ba.gettexture('foo_tex_2')@@ -1371,16 +1371,16 @@ ContextCall has the added bonus that it will not run during context shutdown, whereas ba.WeakCall simply looks at whether the target object still exists. -# example A: code like this can inadvertently prevent our activity -# (self) from ending until the operation completes, since the bound -# method we're passing (self.dosomething) contains a strong-reference -# to self). +# example A: code like this can inadvertently prevent our activity +# (self) from ending until the operation completes, since the bound +# method we're passing (self.dosomething) contains a strong-reference +# to self). start_some_long_action(callback_when_done=self.dosomething)-# example B: in this case our activity (self) can still die -# properly; the callback will clear itself when the activity starts -# shutting down, becoming a harmless no-op and releasing the reference -# to our activity. +# example B: in this case our activity (self) can still die +# properly; the callback will clear itself when the activity starts +# shutting down, becoming a harmless no-op and releasing the reference +# to our activity. start_long_action(callback_when_done=ba.ContextCall(self.mycallback))
@@ -1995,10 +1995,10 @@ ideally just one or two. To include arbitrary values in the description, you can return a sequence of values in the following form instead of just a string: -# this will give us something like 'Score 3 goals.' in English -# and can properly translate to 'Anota 3 goles.' in Spanish. -# If we just returned the string 'Score 3 Goals' here, there would -# have to be a translation entry for each specific number. ew. +# this will give us something like 'Score 3 goals.' in English +# and can properly translate to 'Anota 3 goles.' in Spanish. +# If we just returned the string 'Score 3 Goals' here, there would +# have to be a translation entry for each specific number. ew. return ['Score ${ARG1} goals.', self.settings['Score to Win']]This way the first string can be consistently translated, with any arg @@ -2028,10 +2028,10 @@ ideally just one or two. To include arbitrary values in the description, you can return a sequence of values in the following form instead of just a string:
-# this will give us something like 'score 3 goals' in English -# and can properly translate to 'anota 3 goles' in Spanish. -# If we just returned the string 'score 3 goals' here, there would -# have to be a translation entry for each specific number. ew. +# this will give us something like 'score 3 goals' in English +# and can properly translate to 'anota 3 goles' in Spanish. +# If we just returned the string 'score 3 goals' here, there would +# have to be a translation entry for each specific number. ew. return ['score ${ARG1} goals', self.settings['Score to Win']]This way the first string can be consistently translated, with any arg @@ -2112,7 +2112,7 @@ of a name and a dict of options.
'increment': Value increment for int/float settings.
-# example get_settings() implementation for a capture-the-flag game: +# example get_settings() implementation for a capture-the-flag game: @classmethod def get_settings(cls,sessiontype): return [("Score to Win", { @@ -2672,22 +2672,22 @@ needs a chooser.To see available resource keys, look at any of the bs_language_*.py files in the game or the translations pages at bombsquadgame.com/translate.
-# EXAMPLE 1: specify a string from a resource path +# EXAMPLE 1: specify a string from a resource path mynode.text = ba.Lstr(resource='audioSettingsWindow.titleText')-# EXAMPLE 2: specify a translated string via a category and english value; - # if a translated value is available, it will be used; otherwise the - # english value will be. To see available translation categories, look - # under the 'translations' resource section. +# EXAMPLE 2: specify a translated string via a category and english value; + # if a translated value is available, it will be used; otherwise the + # english value will be. To see available translation categories, look + # under the 'translations' resource section. mynode.text = ba.Lstr(translate=('gameDescriptions', 'Defeat all enemies'))-# EXAMPLE 3: specify a raw value and some substitutions. Substitutions can - # be used with resource and translate modes as well. +# EXAMPLE 3: specify a raw value and some substitutions. Substitutions can + # be used with resource and translate modes as well. mynode.text = ba.Lstr(value='${A} / ${B}', subs=[('${A}', str(score)), ('${B}', str(total))])-# EXAMPLE 4: Lstrs can be nested. This example would display the resource - # at res_a but replace ${NAME} with the value of the resource at res_b +# EXAMPLE 4: Lstrs can be nested. This example would display the resource + # at res_a but replace ${NAME} with the value of the resource at res_b mytextnode.text = ba.Lstr(resource='res_a', subs=[('${NAME}', ba.Lstr(resource='res_b'))])@@ -3028,23 +3028,23 @@ can be specified by providing a tuple of tuples. collision when parts are 'rolling' against each other. Provide a ba.Sound, a target-impulse, and a volume. -# example 1: create a material that lets us ignore -# collisions against any nodes we touch in the first -# 100 ms of our existence; handy for preventing us from -# exploding outward if we spawn on top of another object: +# example 1: create a material that lets us ignore +# collisions against any nodes we touch in the first +# 100 ms of our existence; handy for preventing us from +# exploding outward if we spawn on top of another object: m = ba.Material() m.add_actions(conditions=(('we_are_younger_than', 100), 'or',('they_are_younger_than', 100)), actions=('modify_node_collision', 'collide', False))-# example 2: send a DieMessage to anything we touch, but cause -# no physical response. This should cause any ba.Actor to drop dead: +# example 2: send a DieMessage to anything we touch, but cause +# no physical response. This should cause any ba.Actor to drop dead: m = ba.Material() m.add_actions(actions=(('modify_part_collision', 'physical', False), ('message', 'their_node', 'at_connect', ba.DieMessage())))-# example 3: play some sounds when we're contacting the ground: +# example 3: play some sounds when we're contacting the ground: m = ba.Material() m.add_actions(conditions=('they_have_material', ba.sharedobj('footing_material')), @@ -3187,7 +3187,7 @@ the two nodes exist. The connection can be severed by setting the target attribute to any value or connecting another node attribute to it. -# example: create a locator and attach a light to it +# example: create a locator and attach a light to it light = ba.newnode('light') loc = ba.newnode('locator', attrs={'position': (0,10,0)}) loc.connectattr('position', light, 'position')@@ -4609,15 +4609,15 @@ Real time timers are currently only available in the UI context.the 'timeformat' arg defaults to SECONDS but can also be MILLISECONDS if you want to pass time as milliseconds.
-# example: use a Timer object to print repeatedly for a few seconds: +# example: use a Timer object to print repeatedly for a few seconds: def say_it(): ba.screenmessage('BADGER!') def stop_saying_it(): self.t = None ba.screenmessage('MUSHROOM MUSHROOM!') -# create our timer; it will run as long as we hold self.t +# create our timer; it will run as long as we hold self.t self.t = ba.Timer(0.3, say_it, repeat=True) -# now fire off a one-shot timer to kill it +# now fire off a one-shot timer to kill it ba.timer(3.89, stop_saying_it)
@@ -4802,17 +4802,17 @@ self.t = ba.Timer(0.3, say_it, repeat=True)Think of this as a handy way to tell an object to do something at some point in the future if it happens to still exist.
-# EXAMPLE A: this code will create a FooClass instance and call its - # bar() method 5 seconds later; it will be kept alive even though - # we overwrite its variable with None because the bound method - # we pass as a timer callback (foo.bar) strong-references it +# EXAMPLE A: this code will create a FooClass instance and call its + # bar() method 5 seconds later; it will be kept alive even though + # we overwrite its variable with None because the bound method + # we pass as a timer callback (foo.bar) strong-references it foo = FooClass() ba.timer(5.0, foo.bar) foo = None-# EXAMPLE B: this code will *not* keep our object alive; it will die - # when we overwrite it with None and the timer will be a no-op when it - # fires +# EXAMPLE B: this code will *not* keep our object alive; it will die + # when we overwrite it with None and the timer will be a no-op when it + # fires foo = FooClass() ba.timer(5.0, ba.WeakCall(foo.bar)) foo = None@@ -4830,13 +4830,13 @@ self.t = ba.Timer(0.3, say_it, repeat=True)Instantiate a WeakCall; pass a callable as the first arg, followed by any number of arguments or keywords.
-# example: wrap a method call with some positional and -# keyword args: +# example: wrap a method call with some positional and +# keyword args: myweakcall = ba.WeakCall(myobj.dostuff, argval1, namedarg=argval2)-# Now we have a single callable to run that whole mess. -# The same as calling myobj.dostuff(argval1, namedarg=argval2) -# (provided my_obj still exists; this will do nothing otherwise) +# Now we have a single callable to run that whole mess. +# The same as calling myobj.dostuff(argval1, namedarg=argval2) +# (provided my_obj still exists; this will do nothing otherwise) myweakcall()@@ -5819,7 +5819,7 @@ Real time timers are currently only available in the UI context.the 'timeformat' arg defaults to seconds but can also be milliseconds.
-# timer example: print some stuff through time: +# timer example: print some stuff through time: ba.screenmessage('hello from now!') ba.timer(1.0, ba.Call(ba.screenmessage, 'hello from the future!')) ba.timer(2.0, ba.Call(ba.screenmessage, 'hello from the future 2!'))