Aller au contenu

Photo

Local int. question


  • Veuillez vous connecter pour répondre
16 réponses à ce sujet

#1
bealzebub

bealzebub
  • Members
  • 352 messages
Hey all,
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
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I would actually do as much as I could with the journal itself. An updated journal entry can override a higher one, so you can switch back and forth, and you don't have to tell the player exactly what you're doing in the journal entries. You can even store more than one variable in a single journal by using bitwise operations (i.e. +1 for the triforce of wisdom, +2 for power, and +4 for courage, so 6 means you still need wisdom, and 7 means you're all done. You have journal entries for 10, 11, 12, 13, 14, 15, 16, and 17 to keep track of this part of the quest, with 1-9 for the previous part and 20-29 for the next.)

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
bealzebub

bealzebub
  • Members
  • 352 messages
So it doesn't matter how many variables stack up on say, the module?
Can you still assign a variable to a npc, that's in a different area?

#4
Morbane

Morbane
  • Members
  • 1 883 messages
I remember reading somewhere it was either 256 or 512 - big difference I know but even 256 is a lot of variables.

#5
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
It does matter, but it's a lot before it's an issue. Generally use moderation, and use different objects like waypoints instead of the module itself. The game has to iterate ALL the local ints on an object each time you specify getting the value of one -- it can do this so fast it does not matter, but eventually it will add up.

( 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
Shallina

Shallina
  • Members
  • 1 011 messages
Programmation good practice use of VAR.

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
bealzebub

bealzebub
  • Members
  • 352 messages
thanks everyone, this clears things up a bit, but I'm still left with the question, Can you assign a variable to an object or npc, that's in a different area?

#8
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
yep

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
Alupinu

Alupinu
  • Members
  • 528 messages
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?

#10
MasterChanger

MasterChanger
  • Members
  • 686 messages

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
Alupinu

Alupinu
  • Members
  • 528 messages

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
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
You mean ga_local_int, right? The "tag" parameter is actually the tag of the object (npc, placeable, module, area) that you're attaching the variable to. Then you have the variable name and the value.

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
Alupinu

Alupinu
  • Members
  • 528 messages
Actually LRS the int’s are all global. But sense the puzzle takes place in the same area it would make better sense to make them all local_int.

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
Alupinu

Alupinu
  • Members
  • 528 messages
What is the difference between local and global int?

#15
-Semper-

-Semper-
  • Members
  • 2 259 messages

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
Alupinu

Alupinu
  • Members
  • 528 messages

-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.

Ok now that makes a lot more sense, Thank you Semper.

#17
Shallina

Shallina
  • Members
  • 1 011 messages
The goal of the practices is to avoid to have 2 var that end beeing only one, and then the value is updated when it shouldn't. Bugs appears, and are really hard to solve when this is going on, especially if the "other var" is something made one year or more earlier, or by an other scripter.

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 .