View Single Post
Old 09-26-2011, 10:31 AM   #16
Junior Member
zbyl2's Avatar
Join Date: May 2008
Location: a galaxy far far away...
Posts: 320
Contest winner - Modding  Veteran Modder 
Originally Posted by Qui-Gon Glenn View Post
What I would like to ask the more knowledgable - how would I subroutine-ize the repeated portion of the code, so that I could just have the main script call it twice rather than having the text there for both instances of use? I know I would need to consolidate variables by making oParty (or oParty2, being arbitrary) be assigned to the regular (non-custom) party member. I had tried to do just that, but I am doing something wrong when I try to make subroutines... I think it has to do with where I am declaring my variables
Not sure if it's exactly what you wanted, but it doesn't have same code repeated twice anyway. Probably not the best way to do it, but it should work. I think.
void main()
   object oPC=GetFirstPC();
   object oCustom=GetObjectByTag("p_avix");
   object oParty=GetNextPC();
   object oParty2=GetNextPC();
   object oDoor=GetObjectByTag("man26ad_door02");

   // Define oProper object, which we'll use instead of oParty/oParty2 later.
   object oProper;

   if(oParty != oCustom && oParty2 != oCustom)
      SendMessageToPC(oPC,"Something's screwy around here");
   //figure out who's who
   if(oParty != oCustom) {
         oProper = oParty;
    } else {
     oProper = oParty2;
       // your code, with oParty replaced by oProper.
         AssignCommand(oDoor, ActionOpenDoor(oDoor));
         AssignCommand(oPC, ActionForceMoveToLocation (Location(Vector(420.65048, 164.75064, 8.00), 0.0)));
         AssignCommand(oCustom, ActionForceMoveToLocation (Location(Vector(423.07117, 163.83559, 8.00), 0.0)));
         AssignCommand(oProper, ActionForceMoveToLocation (Location(Vector(419.32086, 165.04903, 8.00), 0.0)));
         DelayCommand(5.0, AssignCommand(oDoor, ActionCloseDoor(oDoor)));

Nice thread by the way QGG - it saved me from boredom of setting up camera angles once more... need to get back to it now, though.
zbyl2 is offline   you may: quote & reply,