Freedom Reborn Archive

Freedom Force Forums => Scripting Forum => Topic started by: bearded on May 10, 2007, 05:34:48 AM

Title: why won't my hero go away?
Post by: bearded on May 10, 2007, 05:34:48 AM
could someone tell me what's wrong with this code, please?
def Retreat():
Mission_CustomAction('Base_Retreat', '', 'building_ff_base_ext', 'Base_Retreat', 16, 2)

def Base_Retreat(event):
heroesList = getAllHeroes()
heronum = len(heroesList)
if heronum >= 2:
ahero=event.object
Object_Destroy(ahero)

script.txt says it wants 2, but only gets 1.  event is the one it wants, what is the other?
Title: Re: why won't my hero go away?
Post by: catwhowalksbyhimself on May 10, 2007, 05:45:41 AM
It really doesn't matter.  Name it whatever you want, Python doesn't care, just as long as there are two variables.
Title: Re: why won't my hero go away?
Post by: bearded on May 10, 2007, 05:59:09 AM
thank you.
i did this:

def Base_Retreat(event, hero):

and got this:
AttributeError: 'string' object has no attribute 'object'
Title: Re: why won't my hero go away?
Post by: catwhowalksbyhimself on May 10, 2007, 06:09:47 AM
It's because of this line

Quoteahero=event.object

Whatever it was you named "event" has nothing named object in it.

Try ahero=hero.object and see if that works.
Title: Re: why won't my hero go away?
Post by: bearded on May 10, 2007, 06:24:01 AM
exact same error.  odd thing is, this code works perfectly:

def OnHeroDeath(event):
ahero=event.object
Object_Destroy(ahero)

ergo, when the hero dies, he is removed from mission.

edit:  and the only thing calling it is :
regDeath('hero', 'OnHeroDeath')
Title: Re: why won't my hero go away?
Post by: catwhowalksbyhimself on May 10, 2007, 06:54:04 AM
Yes, OnHeroDeath uses one set of paramenters, and a custom action another.
Title: Re: why won't my hero go away?
Post by: bearded on May 10, 2007, 07:04:42 AM
here's an interesting thing, this code destroys all existing heroes, no error:
def Base_Retreat(event, ahero):
heroesList = getAllHeroes()
heronum = len(heroesList)
if heronum >= 2:
for ahero in heroesList:
Object_Destroy(ahero)

how to make it stop at the hero that activates the custom?
Title: Re: why won't my hero go away?
Post by: M25 on May 10, 2007, 08:19:40 AM

If you want to call the function from a custom action:


def Base_Retreat(object, hero):
#object is the object/character that had the custom command on it
#hero is the hero that used the custom command
    if len(getAllHeroes()) > 2: Object_Destroy(hero)


If you want to call it from an event or a custom action:

def Base_Retreat(event, hero=None):
#event is an event or the object/character that had the custom command on it
#hero is the hero that used the custom command, or empty if triggered by an event
    if not hero: hero = event.object
    if len(getAllHeroes()) > 2: Object_Destroy(hero)

Title: Re: why won't my hero go away?
Post by: bearded on May 10, 2007, 08:24:53 AM
you guys are so smart.  it seems simple, once you explain it.  thank you!