• Welcome to Freedom Reborn Archive.
 

why won't my hero go away?

Started by bearded, May 10, 2007, 05:34:48 AM

Previous topic - Next topic

bearded

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?

catwhowalksbyhimself

It really doesn't matter.  Name it whatever you want, Python doesn't care, just as long as there are two variables.

bearded

thank you.
i did this:

def Base_Retreat(event, hero):

and got this:
AttributeError: 'string' object has no attribute 'object'

catwhowalksbyhimself

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.

bearded

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')

catwhowalksbyhimself

Yes, OnHeroDeath uses one set of paramenters, and a custom action another.

bearded

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?

M25


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)


bearded

you guys are so smart.  it seems simple, once you explain it.  thank you!