Freedom Reborn Archive

Freedom Force Forums => Scripting Forum => Topic started by: catwhowalksbyhimself on February 07, 2007, 12:55:38 AM

Title: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on February 07, 2007, 12:55:38 AM
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.
Title: Re: Liberty Bay Scripting Help
Post by: M25 on February 07, 2007, 07:19:44 AM
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  ')


Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on February 07, 2007, 09:13:32 AM
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.
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on March 24, 2007, 12:17:19 PM
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
Title: Re: Liberty Bay Scripting Help
Post by: stumpy on March 24, 2007, 02:42:21 PM
Is FFX_InitMission() being called before setMission() in your OnPostInit()?
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on March 24, 2007, 03:00:46 PM
Yes that was all it was.  Sigh.
Title: Re: Liberty Bay Scripting Help
Post by: stumpy on March 24, 2007, 05:18:59 PM
That's good news, right? It could have been something hard to fix...  ;)
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on March 24, 2007, 05:23:01 PM
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.
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on March 24, 2007, 07:23:13 PM
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.
Title: Re: Liberty Bay Scripting Help
Post by: Epimethee on March 24, 2007, 07:29:03 PM
a = randint(1,10)
whichbuild = 'entrance%i' % a

should do the trick (%i = integer, %s = string, %f = float)
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on March 24, 2007, 07:42:28 PM
Alright, thanks, I'll try that.  I'm going to be using this sort of things a few times this mission.
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on August 03, 2007, 08:51:13 PM
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.
Title: Re: Liberty Bay Scripting Help
Post by: Epimethee on August 04, 2007, 06:04:50 PM
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.
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on August 04, 2007, 06:39:25 PM
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?
Title: Re: Liberty Bay Scripting Help
Post by: stumpy on August 04, 2007, 07:22:45 PM
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.)

Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on August 04, 2007, 07:29:06 PM
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.
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on August 07, 2007, 02:59:50 PM
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.
Title: Re: Liberty Bay Scripting Help
Post by: catwhowalksbyhimself on September 01, 2007, 11:16:43 AM
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.
Title: Re: Liberty Bay Scripting Help
Post by: stumpy on September 01, 2007, 01:12:17 PM
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.