Author Topic: Quick question on local variables and scripts  (Read 754 times)

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« on: August 01, 2011, 05:17:42 pm »


               Ok, I'm going to have 2 factions, each with faction appropriate gear.  However, I want to have a dm wand that can be used on the rare occasion that a player wants to change factions, that will not only change the faction in the deity field, but will also loop through the items to check to see if they have a local variable (1 for fate, 2 for chance), and if they have the variable for the faction that you're changing from, the object will be destroyed (so that no one can have opposing faction gear).  I can do most of this (from looking at other scripts), but I don't know how to check variables on possessed objects.  If you can show me this, I can use it in a couple of other scripts, to make things work more nicely.  Thank you in advance for the information.

Alassirana
               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #1 on: August 01, 2011, 05:49:24 pm »


               Like this?


void main()
{
  object oPC = GetItemActivatedTarget();
  if (!GetIsPC(oPC)) return; //End if this isn't a PC

  object oInvItem = GetFirstItemInInventory(oPC);
  while (GetIsObjectValid(oPC)) {
    if (GetLocalInt(oInvItem, "YourFactionVariable")) {
      SetPlotFlag(oInvItem, FALSE);
      DestroyObject(oInvItem);
    }
    oInvItem = GetNextItemInInventory(oPC);
  }
}

               
               

               


                     Modifié par Thayan, 01 août 2011 - 04:49 .
                     
                  


            

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #2 on: August 01, 2011, 06:07:22 pm »


               Thank you very much.  That will work wonders.
               
               

               
            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #3 on: August 02, 2011, 01:50:39 am »


               You don't have to turn off the plot flag to destroy an item.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #4 on: August 02, 2011, 08:21:27 pm »


               

Axe_Murderer wrote...

You don't have to turn off the plot flag to destroy an item.


I'm guessing that is meant as a failsafe in case the item was marked as plot. Turning off the plot flag on a non-plot marked item won't do anything.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #5 on: August 02, 2011, 09:05:15 pm »


               

_Knightmare_ wrote...

Axe_Murderer wrote...

You don't have to turn off the plot flag to destroy an item.


I'm guessing that is meant as a failsafe in case the item was marked as plot. Turning off the plot flag on a non-plot marked item won't do anything.


It doesn't matter if it's checked as plot though. Like Axe said you don't have to set plot to false. You can destroy any plot item, object, or creature via scripting without having to uncheck it's plot flag using the "DestroyObject" function. You just can't destroy them in game via spells or damage. So that is just an unnecessary line in the script. The Lexicon doesn't really clarify this.
               
               

               


                     Modifié par GhostOfGod, 02 août 2011 - 08:22 .
                     
                  


            

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #6 on: August 04, 2011, 01:30:47 pm »


               Ok, I tested out the wand (had to wait until I had a friend available that could test it  for me), and ran into an error, saying that there were 'too many instructions'.  I removed the plot tag line, and it's compiled properly, but it compiled before.  I'll show you the script for your perusal so that you can help me figure out what I'm doing wrong.  The script is called from a conversation, and this is where I'm having the problem (I have 2 versions of this script, one for each faction, but they're just reversed in faction names/item prop names).

void main()
{
 object oPC = GetItemActivatedTarget();
 if (!GetIsPC(oPC)) return; //End if this isn't a PC
 SetDeity(oPC, "Fate");

 object oInvItem = GetFirstItemInInventory(oPC);
 while (GetIsObjectValid(oPC)) {
   if (GetLocalInt(oInvItem, "fate")) {
       DestroyObject(oInvItem);
   }
   oInvItem = GetNextItemInInventory(oPC);
 }
}
               
               

               
            

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #7 on: August 04, 2011, 01:33:27 pm »


               Ok, I finally got to test my wand, and recieved an error of 'too many instructions'.  I have since removed the 'plot tag' line, but haven't had a chance to retest it yet.  However, I'm fairly sure that's not the reason why it didn't work.  The first part of the script worked (changing the faction), it's the part that should have removed my faction armor that did not.  I'll post the script below.  Please help me figure out what I'm doing wrong.  (there are actually 2 nearly identical scripts; I'm only posting one, because the other is only different in which faction it changes you into, and which local variable it calls).

 void main()
{
  object oPC = GetItemActivatedTarget();
  if (!GetIsPC(oPC)) return; //End if this isn't a PC
  SetDeity(oPC, "Fate");

  object oInvItem = GetFirstItemInInventory(oPC);
  while (GetIsObjectValid(oPC)) {
    if (GetLocalInt(oInvItem, "fate")) {
        DestroyObject(oInvItem);
    }
    oInvItem = GetNextItemInInventory(oPC);
  }
}
               
               

               
            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #8 on: August 04, 2011, 01:47:31 pm »


               While loop needs to check for valid inventory item, not valid pc. The pc will never be invalid at the while loop, since earlier in the script it would have ended if that was the case and oPC is never assigned a different value inside the loop, so the loop never ends and eventually you run out of instructions. Since it is the inventory item that changes inside the while loop, that's what you should be checking for to end the loop.

[nwscript]void main()
{ object oPC = GetItemActivatedTarget();
   if( !GetIsPC( oPC )) return; // End if this isn't a PC
   SetDiety( oPC, "Fate" );

   object oInvItem = GetFirstItemInInventory( oPC );
   while( GetIsObjectValid( oInvItem ))
   { if( GetLocalInt( oInvItem, "Fate" )) DestroyObject( oInvItem );
      oInvItem = GetNextItemInInventory( oPC );
   }
}
[/nwscript]
               
               

               


                     Modifié par Axe_Murderer, 04 août 2011 - 12:53 .
                     
                  


            

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #9 on: August 04, 2011, 02:34:10 pm »


               Thanks for catching that.
               
               

               
            

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #10 on: August 04, 2011, 02:39:21 pm »


               Once I corrected the spelling in setDeity, it seems to be ok...though I'll have to wait until later (when a friend is on) to fix it).
               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #11 on: August 04, 2011, 02:42:26 pm »


               Whoops. Sorry about that.
               
               

               
            

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #12 on: August 18, 2011, 03:32:36 pm »


               Ok, I've been looking at the scripts so far, and want to modify my 'teleporter' script to use local variables on the panic button (that takes you back to the teleporation nexus) to bring up options on the portal through conversation (text appears when)...but, although I've looked at the scripts you've shown me, I'm not sure how to have it look at the specific object (I want to do this so I don't have to make the players carry around a half dozen place tokens by the end of the game, and it's multiplayer, so local variables on characters get reset when the server does).  Can you show me how to call the specific variables (such as 'fokual' for fokual city)?

Thanks in advance.

Alassirana
               
               

               
            

Legacy_Alassirana

  • Full Member
  • ***
  • Posts: 103
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #13 on: August 18, 2011, 04:21:16 pm »


               *thinks on it a bit* would the part to check it be:  int GetLocalInt("panicbutton", oPC, "fokual") for example?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Quick question on local variables and scripts
« Reply #14 on: August 18, 2011, 07:24:24 pm »


               Are you talking about a different script now? Not sure what you are asking..