Author Topic: Need help with an easy question.  (Read 567 times)

Legacy_neonscale

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Need help with an easy question.
« on: February 14, 2011, 06:05:24 pm »


               I read through the resources, watched the video tutorials, been playing around with the toolset since 2006... and there is only one thing that i am majorly confused about.

What the heck are "Local Variables'?  How do they work, what can you do with them, and how do you know which kind of variable to create for what.

If someone could please explain this to me or link me to a resource that will explain this, I will be eternally greatful.

Thank you.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Need help with an easy question.
« Reply #1 on: February 14, 2011, 06:32:29 pm »


               Local variables are values stored on any object in game under specific name. They are very commonly used in various custom content script as a workaround for the inability to make a custom GUI in toolset where the builder could set these values. You can set them manually in toolset, every object has a button in its properties (either called "Variables" or "...") mostly on page Advanced.



They are used by default also in any module through so called "Module Switches" which are in fact a Local Variables on the module object which are then read via various scripts in game. The most used one is name of the custom script that is run in the "spellhook" (if you want to know more on this subject I will explain). Scripters have a function to read and modify these variables in their scripts, so amazing thing are possible.



Just a brief example. Lets say that you want to make special script for creature that will spawn secondary creature when this one dies. So, I as your scripter will make you script that instead of using specific values which would then suits only one such creature will read these values from the creature's local variables.



So you set on your creature these variables:

name/type/value

SPAWN_NPC/string/nw_zombie (new creature's resref)

SPAWN_WP/string/wp_zombie (the waypoint with this tag must be somewhere in your module otrewise it would fail)

SPAWN_NUM/int/1 (how many creatures to spawn)



So if you would set these values on your creature and I would provide you such script then after this creature would died, one zombie would appear at the given waypoint.



And you could instead of zombie set a custom creature with another set of variables so the killing madness could continue '<img'>
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need help with an easy question.
« Reply #2 on: February 14, 2011, 06:37:41 pm »


               Tutorial - Celowin - Part II: Local Variables

Local Variables, in NWN, is a list of lables with valuse assosiated with them.  Iit is the way you pass data between scripts in NWN 
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Need help with an easy question.
« Reply #3 on: February 14, 2011, 09:46:01 pm »


               Using variables drasticlaly lowered the amount of unique scripts I had about the place.
Here's a basic and flexible example.

Put a Hay Roll or Bail of Hay in your area.
Make it PLOT (so others won't destroy it) Usable, and Has Inventory.
Tab over to Scripts and under the OnOpen type 'objectloot' and hit  edit. (this should create a script for you real quick.)

copy and paste this into it


void main()
{
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
            string SDROP1 = GetLocalString(OBJECT_SELF, "SDROP1");
            string SDROP2 = GetLocalString(OBJECT_SELF, "SDROP2");
            string SDROP3 = GetLocalString(OBJECT_SELF, "SDROP3");
            string SDROP4 = GetLocalString(OBJECT_SELF, "SDROP4");
            string SDROP5 = GetLocalString(OBJECT_SELF, "SDROP5");
            string SDROP6 = GetLocalString(OBJECT_SELF, "SDROP6");
           
  int sometimesloot = d6();
            if (sometimesloot == 1){CreateItemOnObject(SDROP1);}
            if (sometimesloot == 2){CreateItemOnObject(SDROP2);}
            if (sometimesloot == 3){CreateItemOnObject(SDROP3);}
            if (sometimesloot == 4){CreateItemOnObject(SDROP4);}
            if (sometimesloot == 5){CreateItemOnObject(SDROP5);}
            if (sometimesloot == 6){CreateItemOnObject(SDROP6);}
           
}

Save and close the scripting page and back to your Hay Bale profile page. Hit the Advanced tab and click on the Variable... button.

Under name, add SDROP1, type will be string, value will be needle
Click Add
Repeat this so you have SDROP1 - SDROP3 with needle and SDROP4 - 6 without any value 
Click OK and OK again to exit your Object properties screen.

Now create a needle. I used Miscellaneous Small 2* from the CEP to find a needle. I try and keep the TAG and the ResRef of all my custom items the exactly the same. So in this case, it's named needle

Build and test your module.
You'll see that when you click on the Hay bale, you should see a needle about half the time. Hopefully you can see how this can be very dynamic in the long run.

Here's my full script for object spawning items.


void main()
{
if(GetIsObjectValid(GetFirstItemInInventory(OBJECT_SELF)) || GetLocalInt(OBJECT_SELF,"DO_ONCE")) return;
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
            string SDROP1 = GetLocalString(OBJECT_SELF, "SDROP1");
            string SDROP2 = GetLocalString(OBJECT_SELF, "SDROP2");
            string SDROP3 = GetLocalString(OBJECT_SELF, "SDROP3");
            string SDROP4 = GetLocalString(OBJECT_SELF, "SDROP4");
            string SDROP5 = GetLocalString(OBJECT_SELF, "SDROP5");
            string SDROP6 = GetLocalString(OBJECT_SELF, "SDROP6");
            string SDROP7 = GetLocalString(OBJECT_SELF, "SDROP7");
            string SDROP8 = GetLocalString(OBJECT_SELF, "SDROP8");
            string SDROP9 = GetLocalString(OBJECT_SELF, "SDROP9");
            string SDROP10 = GetLocalString(OBJECT_SELF, "SDROP10");
            string SDROP11 = GetLocalString(OBJECT_SELF, "SDROP11");
            string SDROP12 = GetLocalString(OBJECT_SELF, "SDROP12");
            int sometimesloot = d12();
            if (sometimesloot == 1){CreateItemOnObject(SDROP1);}
            if (sometimesloot == 2){CreateItemOnObject(SDROP2);}
            if (sometimesloot == 3){CreateItemOnObject(SDROP3);}
            if (sometimesloot == 4){CreateItemOnObject(SDROP4);}
            if (sometimesloot == 5){CreateItemOnObject(SDROP5);}
            if (sometimesloot == 6){CreateItemOnObject(SDROP6);}
            if (sometimesloot == 7){CreateItemOnObject(SDROP7);}
            if (sometimesloot == 8){CreateItemOnObject(SDROP8);}
            if (sometimesloot == 9){CreateItemOnObject(SDROP9);}
            if (sometimesloot == 10){CreateItemOnObject(SDROP10);}
            if (sometimesloot == 11){CreateItemOnObject(SDROP11);}
            if (sometimesloot == 12){CreateItemOnObject(SDROP12);}

SetLocalInt(OBJECT_SELF,"DO_ONCE",TRUE);
DelayCommand(600.0,DeleteLocalInt(OBJECT_SELF,"DO_ONCE"));    //10min delay 300.0 is 5min delay
}

               
               

               
            

Legacy_neonscale

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Need help with an easy question.
« Reply #4 on: February 15, 2011, 01:38:20 pm »


               Thank you so much for the help everyone.  They seem to do exactly what I need them to do, and now that I understand them I am confident that my module will be what i was hoping to achieve.
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Need help with an easy question.
« Reply #5 on: February 15, 2011, 09:03:48 pm »


               

Buddywarrior wrote...

Using variables drasticlaly lowered the amount of unique scripts I had about the place.
Here's a basic and flexible example.

Put a Hay Roll or Bail of Hay in your area.
Now create a needle. ]


I loled at this example...needle in a haystack...awesome example, man.