Author Topic: Secondary generators script, close to release testing but...  (Read 3169 times)

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2200
  • Cookies: 1707
  • Life is life
Re: Secondary generators script, close to release testing but...
« Reply #20 on: July 26, 2012, 08:53:03 PM »
Wrong snippet. It's late over here.

Code: [Select]
AddPythonFuncHandlerForInstance
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: Secondary generators script, close to release testing but...
« Reply #21 on: July 27, 2012, 10:06:14 PM »
Wrong snippet. It's late over here.

Code: [Select]
AddPythonFuncHandlerForInstance
Wrong snippet?

How do I get a function to fire when an already existing button is clicked?

There are no examples at hand of using AddPythonFuncHandlerForInstance(). I've only ever setup handlers for buttons when i've  created them.

I've tried:
Code: [Select]
pSaffiQB.AddPythonMethodHandlerForInstance(App.ET_ST_BUTTON_CLICKED, __name__ + ".CombatEnded")and failed.
Great men are not peacemakers! Great men are conquerors!

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2200
  • Cookies: 1707
  • Life is life
Re: Secondary generators script, close to release testing but...
« Reply #22 on: July 27, 2012, 11:11:30 PM »
I thought it was obvious that you should just replace
Code: [Select]
RemoveHandlerForInstance
to
Code: [Select]
AddPythonFuncHandlerForInstance

in the sample I posted???
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: Secondary generators script, close to release testing but...
« Reply #23 on: July 28, 2012, 01:20:40 PM »
I thought it was obvious that you should just replace
Code: [Select]
RemoveHandlerForInstance
to
Code: [Select]
AddPythonFuncHandlerForInstance

in the sample I posted???
As dumb as I feel, it's still a no go  :doh:
CombatEnded() is not called when the button is clicked.

Code: [Select]
def GetMenuButton(sMenuName, sButtonName):
        pMenu = Lib.LibEngineering.GetBridgeMenu(sMenuName)
        if not pMenu:
                return
        # Grab the starting button.   
        pButton = pMenu.GetButton(sButtonName)
        if not pButton:
                pButton = pMenu.GetSubmenu(sButtonName)
                if not pButton:
                        return
        return pButton

def CombatEnded(pObject, pEvent):
print "COMBATENDED()"

pSaffiQB = GetMenuButton("Commander", "End Combat")       
if pSaffiQB:
pSaffiQB.AddPythonFuncHandlerForInstance(App.ET_ST_BUTTON_CLICKED, __name__ + ".CombatEnded")
        print "handler added"
"handler added" appears in the log.
After clicking "End Combat" "COMBATENDED()" isn't present in the log.
Great men are not peacemakers! Great men are conquerors!

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2200
  • Cookies: 1707
  • Life is life
Re: Secondary generators script, close to release testing but...
« Reply #24 on: July 28, 2012, 03:17:30 PM »
Why it's not working?
I'm not sure, maybe I missed something. I don't want to go deep into scripts we developed 7 years ago nor I have the time to ask Wowbagger.

What can you do?

You can always do the following:
Code: [Select]
def EndSim(pObject, pEvent):
        pass
           
def init():
        import QuickBattle.QuickBattle
        App.g_kEventManager.AddBroadcastPythonFuncHandler(QuickBattle.QuickBattle.ET_END_SIMULATION, MissionLib.GetMission(), __name__ + ".EndSim")

Why we chose to use the following implementation instead of the one which I'm presenting now?
I cannot remember, it was 7 years ago. I'm pretty sure Wowbagger had a good reason.

Notes:

It is imperative that you study the QuickBattle.py, MissionLib.py and scripts located in the Bridge directory. Most of the answers are located there for you ;)
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: Secondary generators script, close to release testing but...
« Reply #25 on: July 28, 2012, 09:36:01 PM »
Why it's not working?
I'm not sure, maybe I missed something. I don't want to go deep into scripts we developed 7 years ago nor I have the time to ask Wowbagger.

What can you do?

You can always do the following:
Code: [Select]
def EndSim(pObject, pEvent):
        pass
            
def init():
        import QuickBattle.QuickBattle
        App.g_kEventManager.AddBroadcastPythonFuncHandler(QuickBattle.QuickBattle.ET_END_SIMULATION, MissionLib.GetMission(), __name__ + ".EndSim")

Why we chose to use the following implementation instead of the one which I'm presenting now?
I cannot remember, it was 7 years ago. I'm pretty sure Wowbagger had a good reason.
Thanks, the function now fires when "End Combat" is clicked just as I wanted. Hopefully whatever the reason came up with 7 years ago for not using this method of implementation wasn't a very good one and I can happily transfer it from the test script to the secondary shield generators script  :D


Notes:

It is imperative that you study the QuickBattle.py, MissionLib.py and scripts located in the Bridge directory. Most of the answers are located there for you ;)
Thanks for the tips Sov.

The BC API is so daunting to me not only because I don't fully understand the features and concepts (Object Oriented mostly) of the language it's all written in but mostly because the pre-made framework is so huge I get overloaded with what's in front of me.

Still, i'll try more not to bother you with every little thing of how to do X without going for a walk through the BC .py's  :)

P.S: What happened to "USS Sovereign:lostit:
Great men are not peacemakers! Great men are conquerors!

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2200
  • Cookies: 1707
  • Life is life
Re: Secondary generators script, close to release testing but...
« Reply #26 on: July 28, 2012, 10:54:25 PM »
Quote
P.S: What happened to "USS Sovereign"

I changed it to my real first name. It's also always fun to confuse people.
Acta, non verba.
aka USS Sovereign

Offline CyAn1d3

  • MacDill Shipyards Design Team
  • Posts: 1656
  • Cookies: 420
  • RETIRED
Re: Secondary generators script, close to release testing but...
« Reply #27 on: July 28, 2012, 11:35:19 PM »
I changed it to my real first name. It's also always fun to confuse people.

the avatar mate  :evil:
I came, i saw, i added a Sig.
Later gents, i have Youtube to take over.
Cy - 1-12-15

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2200
  • Cookies: 1707
  • Life is life
Re: Secondary generators script, close to release testing but...
« Reply #28 on: July 29, 2012, 02:51:01 AM »
Quote from: CyAn1d3
the avatar mate

You know... you could have at least pretended not to notice... you see... I'm a webmaster which is a rank equal to vice-admin on these forums... I'm just saying... :funny

Now on a serious note, I should change my avatar thanks for reminding me.

Quote from: Bat66wat6
The BC API is so daunting to me not only because I don't fully understand the features and concepts (Object Oriented mostly) of the language it's all written in but mostly because the pre-made framework is so huge I get overloaded with what's in front of me.

In all honesty, we all learned it through trial an error, it's not a shame to ask. I'm just trying to point you in the right direction.
Acta, non verba.
aka USS Sovereign

Offline CyAn1d3

  • MacDill Shipyards Design Team
  • Posts: 1656
  • Cookies: 420
  • RETIRED
Re: Secondary generators script, close to release testing but...
« Reply #29 on: July 29, 2012, 06:53:02 PM »
You know... you could have at least pretended not to notice... you see... I'm a webmaster which is a rank equal to vice-admin on these forums... I'm just saying... :funny

ooops  :hide

Now on a serious note, I should change my avatar thanks for reminding me.

i know the feeling.... so do i
I came, i saw, i added a Sig.
Later gents, i have Youtube to take over.
Cy - 1-12-15