• Welcome to Freedom Reborn Archive.
 

Liberty Bay Scripting Help

Started by catwhowalksbyhimself, February 07, 2007, 12:55:38 AM

Previous topic - Next topic

catwhowalksbyhimself

I figure the other topic is somewhat different, so for non-basic scripting stuff, I figured I'll just make a new thread.

I have this bit of code:


def disablecycleover(event):
print "animation cycle ended"
status = int(event.data)
if status:
print "cycle complete!"
if Mission_GetAttr('whichone') == 1
addAttr('finished_cycles1', 1)
print Mission_GetAttr('finished_cycles1')
if Mission_GetAttr('whichone') == 2
addAttr('finished_cycles2', 1)
print Mission_GetAttr('finished_cycles2')
if Mission_GetAttr('finished_cycles1') == 10:
addAttr('finished_both', 1)
if Mission_GetAttr('finished_cycles2') == 10:
addAttr('finished_both', 1)
if Mission_GetAttr('finished_both') == 2:
play(whitelfree_cs, "whitelfree_cs")
if Mission_GetAttr('whichone')=1
disablefield('sc_blitz_shield_em


Which give me this error:

  File "C:\Documents and Settings\Compaq_Owner\Local Settings\Application Data\Irrational Games\Freedom Force vs the 3rd Reich\temp\mission.py", line 101
    if Mission_GetAttr('whichone') == 2
                                      ^


And I can't for the life of me see anything that I did wrong.

Note that most of this code is adapted from the Sky King suit fixing code.

M25

There are a few syntax errors.


def disablecycleover(event):
print "animation cycle ended"
status = int(event.data)
if status:
print "cycle complete!"
if Mission_GetAttr('whichone') == 1                             <- missing colon
addAttr('finished_cycles1', 1)
print Mission_GetAttr('finished_cycles1')
if Mission_GetAttr('whichone') == 2                              <- missing colon
addAttr('finished_cycles2', 1)
print Mission_GetAttr('finished_cycles2')
if Mission_GetAttr('finished_cycles1') == 10:
addAttr('finished_both', 1)
if Mission_GetAttr('finished_cycles2') == 10:
addAttr('finished_both', 1)
if Mission_GetAttr('finished_both') == 2:
play(whitelfree_cs, "whitelfree_cs")
if Mission_GetAttr('whichone')=1                                  <- missing colon and should be ==
disablefield('sc_blitz_shield_em                            <- missing closing quote and parenthesis  ')



catwhowalksbyhimself

Yeah, I'm bad about missing those colons.  I guess I should have slept on it first.  The problem was pretty obvious, but getting a second set of eyes can be helpful.  Thanks.

catwhowalksbyhimself

I'm getting a strange traceback error in Mission 5 that I'm not sure about.

QuoteMLOG_Init(keepRunningModules=0): starting up
mlogreader.MLOG_Init: current mission = '05_POWER'
Traceback (innermost last):
  File "C:\Documents and Settings\Compaq_Owner\Local Settings\Application Data\Irrational Games\Freedom Force vs the 3rd Reich\temp\mission.py", line 17, in OnPostInit
    FFX_InitMission()
  File "C:\Program Files\Irrational Games\Freedom Force vs The 3rd Reich\.\liberty_bay\missions\scripts\ffx.py", line 253, in FFX_InitMission
    initialise(0)
  File "C:\Program Files\Irrational Games\Freedom Force vs The 3rd Reich\.\liberty_bay\missions\scripts\ffx.py", line 302, in initialise
    if ( not skirmish ) and ( cshelper.getMission()<23 ): # Kuertee 2006-07-30 #cshelper.getMission () fails when "initialise (skirmish = 1)" is called
  File "cshelper.py", line 1177, in getMission
    return int(Mission_GetAttr('_cs_mission_number'))
RuntimeError: Unknown attribute - _cs_mission_number

stumpy

Is FFX_InitMission() being called before setMission() in your OnPostInit()?

catwhowalksbyhimself

Yes that was all it was.  Sigh.

stumpy

That's good news, right? It could have been something hard to fix...  ;)

catwhowalksbyhimself

Yes, it is, but now that this comes up, I could swear that I did the exact same thing with an earlier mission and posted here pre-wipe about it.

Oh well.  Moving on.

I'm likely to have lots of real things happen this mission.  It's an experimental mission, and is largely random in nature.

catwhowalksbyhimself

Now I need help with Python syntax.

I'm trying to combine a string with a number to make a new string.

The line I'm trying to use is:


[quote]
a = randint(1,10)
whichbuild='entrance'+a[/quote]


But that obviously isn't right.

Epimethee

a = randint(1,10)
whichbuild = 'entrance%i' % a

should do the trick (%i = integer, %s = string, %f = float)

catwhowalksbyhimself

Alright, thanks, I'll try that.  I'm going to be using this sort of things a few times this mission.

catwhowalksbyhimself

Okay, another dumb question here.

I'm trying to set up a custom command to appear whenever Doc Astounding's on a mission.  I can get the command to appear, no problem, but only when any hero is allowed.  I can't figure out how to get it to work for Doc only.

This:

addCustomCommand('scan', building, 'scan_door', oneshot = 1, radius = 20, hero = 'doc_astounding', attentionMarker = 1)

Does not seem to work.

Epimethee

You've probably already triple-checked it already, but just in case, is the doc character indeed named "doc_astounding" in this mission?

Otherwise, I'd try the non-cshelper version (Mission_CustomAction()) and if it works, add the attention marker manually.

catwhowalksbyhimself

That's the template name, but if he's selected on a mission, does that mean the game gives him some sort of random name?  If so, how can I identify him?

stumpy

If he's selected by the player, rather than required for the mission, then his in-mission object name will be something like 'hero_2'. To get the name of the character (as I recall, he doesn't shapeshift, clone or anything), try
doc = filter(lambda o: Object_GetTemplate(o)=='doc_astounding',Mission_GetDynamicObjects())
if len(doc)==1: # we found him
    doc = doc[0]
    addCustomCommand('scan', building, 'scan_door', hero = doc)
    # (Or put in the loop where you define building.)


catwhowalksbyhimself

Thanks, Stumpy.  That's the kind of answer I'll be looking for.  Since I'm aiming for Doc to do Scientific stuff like the Spider and Fly in Strangers, I'll be needing this a lot.  This is just the first mission where you could really choose a squad, and thus the first mission where he might not be there.

catwhowalksbyhimself

Yet another thank you. I tested it, and unlike most things in my coding, it worked perfectly the first time.  As I said, most missions will need this.

catwhowalksbyhimself

Sorry for not getting back sooner, but it's been busy of late.  That, and I discovered the new Dr. Who series on Netflix's online service.

Anyhow, the code only works if Doc is on the team.  If he doesn't, I get an error message and the mission comes crashing down.

I'll try to post the actual error message soon.

stumpy

Hmmm. That code shouldn't break if it doesn't find doc's template. Are you using the doc variable outside the if statement? If he isn't on the mission, doc is an empty list, that's why I check for length before using it. If you are seeing a "index out of range" error, then that's probably what's going on. I'll take a look when you post.