Local int. question
#1
Posté 13 mai 2012 - 04:09
Over the last few weeks I've been doing a lot of side-quest type conversations, and I've been using local ints to keep track of everything. Some times the target is $MODULE, sometimes $PC, sometimes the npc speaker. It just sort of depends on the conversation.
I was wondering, is there somewhere that is better than others to assign the variables to? I could have just assigned them all to $MODULE, and it would work fine. I didn't know if it would matter anywhere if $MODULE had hundreds of variables assigned to it. Or what would happen if I assigned every variable in the whole campaign to the PC? Would it matter?
#2
Posté 13 mai 2012 - 04:37
The great thing about using the journal is that it's really easy to check up on it, and really easy to adjust it using standard console commands.
Using $PC can get you in trouble if it winds up refering to different party members at different times, depending on who walks through that trigger first or lands the killing blow. The journal functions already allow you to change the journal for the whole party at once.
Using the module to store variables is more stable, but you have be careful not to mix up variables from different quests. An npc speaker with a unique tag can work well, too, especially if they're just involved with the one quest. Another option is a quest item, either as a token itself of the quest state, or as an object to attach variables to. Item variables can be carried over from module to module, without worrying about a campaign database. Again, though, you have to keep track of all those variables, which the journal does quite neatly.
#3
Posté 13 mai 2012 - 04:53
Can you still assign a variable to a npc, that's in a different area?
#4
Posté 13 mai 2012 - 05:39
#5
Posté 13 mai 2012 - 05:46
( the dmfi for example does thousands, and the AI does quite a few, so if you do just 500 it might tip it over the edge of causing real problems because you are not the only one doing it-- seem to remember some of the old timers saying it's upwards of 5000 vars before you start seeing issues. )
#6
Posté 13 mai 2012 - 07:26
Always use the smaller "context".
If the convo is only related to one NPC, store your VAR into that NPC.
if the convo is related to many event in one AREA and those event can affect each other in different convo of that AREA, use the AREA to store the VAR.
if the event and convo related to it are spread all over the module, store the VAR in the module.
if the event and convo related to it are spread all over the campaign, store the VAR as GlobalInt/string ect.. not campaign VAR. Campaign VAR are unafected by save game wich could be very usefull if you wants things that can be tried only the "first time" for exemple, but it's a bug nest if the player reload a game in a previous state.
Global var name cannot be used by 2 or more global var, you need to track them wich is a constraint next to local var where that rules only apply to the object where they are stored.
Tracking event with journals entry is also not a bad Idea since the journal forfeit the use of the same name.
Storing Var in the PC is dangerous, he's always bring his Var with him wich make them work as global Var.
#7
Posté 13 mai 2012 - 01:22
#8
Posté 13 mai 2012 - 01:49
you can get objects by tag.
You can create waypoints dynamically in game and use them for storage as well. This is the smallest type of object that can store them, and it's even got a function to get a way point by tag.
#9
Posté 13 mai 2012 - 05:12
#10
Posté 13 mai 2012 - 05:38
Alupinu wrote...
Wow, I thought you can give local int variable any tag you want. After reading this I wondering if maybe I have a lot of rework to do or maybe I'm just not understanding the post correctly. Anyway i guess my question is why do you have to assign a var to anything? Why can't you just give the var a unique tag and leave it at that?
Because the variable is in reference to something. If it's about one character in particular, you attach it to that character. If it is related to a specific area, you attach it to that area.
If you really want it to totally general, you can make it a global variable. Globals are not attached to any object but retrieved just by name. I find that most times that you want something general, however, it's best to attach it to the module itself.
#11
Posté 13 mai 2012 - 06:32
MasterChanger wrote...
Alupinu wrote...
Wow, I thought you can give local int variable any tag you want. After reading this I wondering if maybe I have a lot of rework to do or maybe I'm just not understanding the post correctly. Anyway i guess my question is why do you have to assign a var to anything? Why can't you just give the var a unique tag and leave it at that?
Because the variable is in reference to something. If it's about one character in particular, you attach it to that character. If it is related to a specific area, you attach it to that area.
If you really want it to totally general, you can make it a global variable. Globals are not attached to any object but retrieved just by name. I find that most times that you want something general, however, it's best to attach it to the module itself.
Ic… Thank you MC. Well the reason I’m asking is I have is a puzzle set up in conversations. The puzzle itself is three valves, each valve has its own conversation, that have to be turned a set number of times in the right sequence to unlock the puzzle. Each valve has a ga_int variable of 1 and the conditional has a gc_int variable of ‘=3’ that unlocks the puzzle. All these variables are assigned to the same tag but not to a character, object or module. The puzzle seems to work fine. Does this make any sense? LOL
#12
Posté 13 mai 2012 - 07:08
With object-oriented programs in general, and NWN2 specifically, you have to assume that the variables go on to live their lives in a spirit of sheer anarchy and capricious growth and decline. Your little puzzle variables might be secure out in their little homestead for now, but before you know, a whole city of puzzles have grown up around them, and all kinds of riff-raff starts picking through that little homestead, each insistent that they bought the place from a guy in Brooklyn just last week, and this other guy named "iDoOnce" insists that the house has been condemned for demolition.
So keep track of your variables, if you can, but keep them protected, give them unique names, and keep their scope small.
#13
Posté 13 mai 2012 - 08:13
This whole int’ll thing really sounds like a dog eat dog world. And that guy from Brooklyn? Yea, I know his type.
So… the tag of my variable is attached to my conversation node? I really don’t see what else it could be attached too. The valve object only opens the conversation and the int conditional is just a trap door that goes true when all three ga_int have been fired (which are attached to specific nodes.) or when my tag has accumulated =3.
#14
Posté 13 mai 2012 - 08:18
#15
Posté 13 mai 2012 - 08:29
Alupinu wrote...
What is the difference between local and global int?
a local int is a variable which is stored at an object and can be referenced within the module. a global int is a variable which needs no object to be stored and can be referenced within the whole campaign.
#16
Posté 13 mai 2012 - 08:40
Ok now that makes a lot more sense, Thank you Semper.-Semper- wrote...
Alupinu wrote...
What is the difference between local and global int?
a local int is a variable which is stored at an object and can be referenced within the module. a global int is a variable which needs no object to be stored and can be referenced within the whole campaign.
#17
Posté 13 mai 2012 - 10:54
2 VAR with the same name but stored in an different object are disctinc.
Possible application : Storing each NPC real names into a local VAr "name" stored into them and give them the "commoner" name.
when the player speak to them he get to know them, and then you change the "commoner" name into their real name with the same function each time by getting it from the local VAr stored in the NPC the player just speaked to.
Modifié par Shallina, 13 mai 2012 - 11:04 .





Retour en haut







