Can someone define constants
#1
Posté 03 mai 2010 - 11:23
#2
Posté 04 mai 2010 - 12:37
The reason for constants is to avoid typos, to make it easier to track down which tags/resources are used in scripts and to allow changes to be made quickly. Putting the constants in include files allows them to be used in multiple different scripts, and to change all of those scripts by making just one change, so I recomend doing so. You can declare constants in the script that contains the main/startingconditonal function, but if you ever find yourself using that same constant somewhere else I advise moving it to an include file rather than duplicating the definition.
As an example, say you are making a quest for the player to bring the magic gem to the mystic mountain. When the player talks to the quest giver, he gives them the gem. You could use the resource literal in the script, but then you're going to have to potentialy use it again when you take away the gem. That's two places you could make a typo, and it's also two places you have to remember to change if you ever change the resource name. Who knows, maybe you change your mind and make it a magic ring instead, and don't like working with the out of date resource names. With a constant declared in an include file, you can type out the literal only once, and use the constant everywhere else.
Constants can also be used for more mathmatical purposes with integers or floats. Perhaps you have a heartbeat system that sends events every 1.0 seconds, and does so from mutliple places in multiple scripts. If you make it a constant, you can easly increase or decrease the delay time across all scripts by changing it in the one place. Or maybe you have a system that spawns new oppontents into a fight, to maintain 10. If you use a constant, you can change it to 12 more easily.
I also like to use constants to provide more descriptive names. Strings are resources are limited in length, and sometimes are named based on conventions that don't include the player facing name. The various equipable items the player gets in origins have particularly unhelpful names.
#3
Posté 04 mai 2010 - 12:57
Consider an event script without constants. It would be hard to read as it would be case 3 here and case 4 there and not forgetting case 25 somewhere else. Using constants makes it much easier as it gives meaning to these values: namely EVENT_TYPE_SPAWN, EVENT_TYPE_DEATH and EVENT_TYPE_PERCEPTION_APPEAR.
Modifié par Sunjammer, 04 mai 2010 - 12:58 .
#4
Posté 05 mai 2010 - 06:55
Update -
I just answered my own question - if I set a constant in my module, then go to single player without restarting DA, the constant is still set...is there an event for quitting out of a module (I would use that to re-init the constant to 0, thus avoiding my event override script).
Modifié par RecklezzRogue, 05 mai 2010 - 07:59 .
#5
Posté 05 mai 2010 - 08:21
My best guess as to what is happening to you is that the exported version of something is being put in a global override directory and effecting modules you don't intend it to.
A more concrete example of what you are doing would help.
#6
Posté 05 mai 2010 - 10:44
I have developed some EVENT intercepts to help with odd NPC behaviours (taunting but not attacking during combat, not returning to home after combat, and just standing around after an AOE (Command Complete = 32).
see http://social.bioware.com/forum/1/topic/71/index/1326927/2#2520131 if you care to see the script, and all the trial and error getting me to this point.
The Event Intercept script appears to cause issues with awakenings (so I am assuming it is generally a compatibility issue), and besides that, I want my module to be as self-contained as possible...not to interfere with anything else.
So - what I have done is the following:
#1 - create an engineevents.gda which overrides EVENT_TYPE_COMMAND_COMPLETE and EVENT_TYPE_PERCEPTION_DISAPPEAR to my override script (dmo001_event_intercept.nss). This gda is in my ../addin/mymodule/core/override/
#2 - create my event intercept script, with a check at the top of each "case EVENT_TYPE" that the constant DMO001_EVENTS_OVERRIDE = 1, else it will send the events to their respective default handlers (creature core and rules core).
case EVENT_TYPE_PERCEPTION_DISAPPEAR:
{
// If this isn't Dark Alliances, bail to default handler
//
object oModule = GetModule();
if (GetLocalInt(oModule, "DMO001_EVENTS_OVERRIDE") == 0)
{
DisplayFloatyMessage(GetHero(), "Event Int Exit - Line 42", FLOATY_MESSAGE, 16777215,5.0); //Debug
HandleEvent(ev,RESOURCE_SCRIPT_CREATURE_CORE);
}
#3 - create a constants script (dmo001_module_constants_h) which initializes DMO001_EVENTS_OVERRIDE = 0
const int DMO001_EVENTS_OVERRIDE = 0;
#4 - Change the value of my constant as follows in my module core script (this is where you know I am not a programmer...lol...if not already)
switch(nEventType)
{
case EVENT_TYPE_MODULE_START:
{
// Setting up event intercepts to only work with this module
//
object oModule = GetModule();
SetLocalInt(oModule, "DMO001_EVENTS_OVERRIDE",1);
#5 - Moved my Intercept script and my constants script to ../addin/dmo001/core/override
Hopefully this will be an easy answer for you! Thanks much for responding.
#7
Posté 05 mai 2010 - 11:09
Here’s what I can tell you. If you're intercepting an event and running GetLocalInt(oModule, "DMO001_EVENTS_OVERRIDE") and that's returning something other than 0, then one of three things is happening. One is that the variable has a default value that isn't 0. Two is that the module variable table has been changed to have a starting value that isn't 0. Three is that in some script, somewhere, SetLocalInt(oModule, "DMO001_EVENTS_OVERRIDE",1); is being run.
Most likely we're looking at the last option. Are you modifying module_core, or are you making a new script and setting it as your module script? If you're modifying module_core, that may be exported into an override directory that's effecting all campaigns. Instead of modifying module_core, make a new script, and pass the event to module_core at the end. Assign the new script as your module's script.
For this however, you don't even need a custom script. Instead of assigning the variable through script, open your module, go to manage modules, select your module, hit properties and find the variables table. Click on that, find your variable, and set the value to 1 instead of 0. Only your module will have that variable set, so you shouldn't have any problems in other modules.
edit: to be clear, have you tried running single player with restarting DA? Are you sure that the problem only surfaces when you run your module first?
Modifié par DavidSims, 05 mai 2010 - 11:12 .
#8
Posté 05 mai 2010 - 11:24
DavidSims wrote...
Most likely we're looking at the last option. Are you modifying module_core, or are you making a new script and setting it as your module script? If you're modifying module_core, that may be exported into an override directory that's effecting all campaigns. Instead of modifying module_core, make a new script, and pass the event to module_core at the end. Assign the new script as your module's script.
RR --> I am not modifying any core scripts, have created my own module_core, area_core, etc.
DavidSims wrote...
For this however, you don't even need a custom script. Instead of assigning the variable through script, open your module, go to manage modules, select your module, hit properties and find the variables table. Click on that, find your variable, and set the value to 1 instead of 0. Only your module will have that variable set, so you shouldn't have any problems in other modules.
RR --> I believe this will solve my problem - I did not know about the manage modules 'tool' capability to set variables...that's great news!
DavidSims wrote...
edit: to be clear, have you tried running single player with restarting DA? Are you sure that the problem only surfaces when you run your module first?
RR--> Becuase i was getting a bit disorderly at that point, I can't say for sure...I will report back once I get through your advice above and run some additional tests (while taking more proper notes)
Sincerely appreciate the help!
#9
Posté 06 mai 2010 - 01:29
1 - created a 2da override for var_module wherein the variable DMO001_EVENT_INTERCEPT is defined as an int with a default value of '0'
2 - used Manage Modules/Properties/Variables to set DMO001_EVENT_INTERCEPT to '1'
3 - check for value of DMO001_EVENT_INTERCEPT in my events override script as follows:
case EVENT_TYPE_PERCEPTION_DISAPPEAR:
{
// If this isn't Dark Alliances, bail to default handler
//
object oModule = GetModule();
if (GetLocalInt(oModule, "DMO001_EVENT_INTERCEPT") == 0)
{
HandleEvent(ev,RESOURCE_SCRIPT_CREATURE_CORE);
}
4 - Placed my engineevents.gda, my var_module.gda, dmo001_event_intercept.nss & ncs in ../addin/core/override
And everything works...now I'll post this where someone trying to solve this will find it - clearly the wrong thread now that I found the root cause...
THANK YOU!
ps - i did not bother with the other testing...if you are curious, I will..else...moving on ;-)





Retour en haut






