Ga_local_int (bug!?)

I had the rare need where I tried to pass =-1 (to set the value to -1) as a value using ga_local_int.

As an example, in the comments, it says, “=-2” (Set to -2).

In my own tests, however, this does not appear to be the case. All it does, is simply do the same thing as passing -1 to the original var. So, for example, when the var is currently 2, and I want to set it to -1, I should be able to use the =-1 to set it. However, it sets it to 1.

Can anyone else confirm or deny this activity, in case I have done something wrong?

that function is just a very pompus/snoobish wrapper for :
SetLocalInt(object,string,int) wicht works perfectly I use it all the time. So why you don’ t have your value ?

Always the same cause, always the the same trouble, all the problems are in the object where your store it.

Be sure the object where your store your value is the same object where you want to fetch it. And check also that the wraper around SetLocalInt(object,string,int) does correctly its job.

1 Like

@Shallina

I am familiar with the default SetLocalInt function, but this wrapper conversation option does normally allow for some useful uses for this variable handling. :slight_smile: (Although, in this case, I am currently using my own function for the purpose here, as this does not appear to do what it says.) I.e. what function do you use when comparing ints in a conversation?

Having tested some more, I am 100% sure the object is correct, as debug confirms. (I will keep testing some more in case I missed something though.)

The point is, this is otherwise a very handy conversation function, which I am sure many would use without possibly noticing this error, especially as it is a side of the function that may be rarely required.

P.S. I suspect the error is somewhere in the CalcNewIntValue function handling, where it fails to have the “=” recognise the negative value as requiring replacement.

1 Like

SetLocalInt(object,string,int) works perfectly
GetLocalInt(object,string) works perfectly everything turns around those 2 function

The ga_ calls the SetLocalInt the gc calls the GetLocalInt.

It can be super powerfull when used beceause you can dissociate several object/actions while using the same script for them.

But you need to be sure that the object where you set or get the value are the “good one”.

ga_setlocal_value_int

void main(string sTag,string sVariable,int iValue){

object oObjectStoredIn = GetObjectByTag(sTag);
SetLocalInt(oObjectStoredIn,sVariable,iValue);

}

int gc_getlocal_value_int

int StartingConditional(string sTag,string sVariable){

object oObjectStoredIn = GetObjectByTag(sTag);
int iValue = GetLocalInt(oObjectStoredIn,sVariable);
return iValue;

}

Those are the same functions without the wrappers. If it doesn’t work the answer is always the same :

you don’t fetch the same object with

object oObjectStoredIn = GetObjectByTag(sTag);

or sVariable hasn’t the same value

The object where you store the value in and the variable you use to name your data have to be the same with the Get function and Set function.

You give me an “Int” but ask someone else the “int” you gave me. That other person won’t give you your “int” back. You need to ask me !

I didn’t use NWN2 default wrapers for storing value, i wrote mine which are usaully super “short and dumb”

SetLocalInt(OBJECT_SELF,sVar,iValue);
int myValue = GetLocalInt(OBJECT_SELF,sVar);

I store the value in OBJECT_SELF, the Area GetArea(oObject) or the module GetModule()

If you use GlobalInt to access it everywhere you need to be sure the different modules are set correctly in the same campaign.

SetCampaignInt are absolute value that be fetch from one campaign to an other on 2 different gamplay session save and on. They are permanent and tied to the computer where they are saved.

SetGlobalInt are tied to the campaign and the save . the are “normal global variable”

SetLocalInt are tied to the object where you save them.

if the object where you store them is deletted or “killed” then destroyed, you won’t be able to access that object and will only get a 0.

Completly unrelated :

I used the trick you found for launching a movie with an XML file so it doesn 't have to be at the begining or the end of a mod, it works perfectly.

1 Like

@Shallina

Thanks! :+1:

Thank you for your detailed response, however, you may wish to consider …

I am aware of how to use the Set/Get Local Int/String/Float/Object variables. I also use Set/Get Global and Set/Get Campaign equivalents throughout my coding. I must have used them many times in my modules. :slight_smile: I even wrote a tutorial trying to explain how to use them for others.

But, I do like to store local variables locally, wherever possible, and not just by using OBJECT_SELF, module or area. Sometimes, I like to use the function to alter a variable on another target, or check on another target … sometimes because I have to.

Now, most of the times, the wrapper function ga_local_int works flawlessly, except (as I post here) in this rather unusual usage of it, when I am trying to set a particular negative value. In all my years of coding, this has never been required (as far as I recall - and in a conversation), but I have just encountered this for the first time, and pass it along as information to others who may also sometimes like to check for negative variables on a local object. E.g. I like to set an int to -1 rather than zero sometimes.

In this particular situation, I had a variable that could be in either “1”, “2” or “0” and when totally finished, “-1”. Therefore, when jumping from a local variable setting that may be “2” using the function to set to “-1”, it failed … it did not do what it said it would do. (It set 2 to 1 instead.)

For this kind of requirement, moving forward, I will use this edited version of the function …

See TRAVUS script below for fixed version.

The reason why I like to use the ga_local_int in other conversation situations, is because it handles additions and subtractions on a value very well (rather than set absolutes), which is very handy when handling conversation nodes. E.g. Passing ++ or - - is a very easy way to add or subtract from the current integer value.

The problem must be with the wraper to be more specific it lies with CalcNewIntValue

that function doesn 't take the “-” sign as negative value but as substract value.

check ginc_var_ops the default wrappers don’t set the value it computes it.

if you want it to work, you need to complete CalcNewIntValue in ginc_var_ops

@Shallina

Yes, you may have missed my earler edited post … :slight_smile:

In this case, I think that would be more trouble than its worth. :wink:

But, at least I have drawn it to attention now. :slight_smile:

Try this new ga_local_int script:

#include "ginc_param_const"
#include "ginc_var_ops"

void main(string sVariable, string sChange, string sTarget)
{
    object oTarg = GetTarget(sTarget, TARGET_OBJECT_SELF);
	int nOldValue = GetLocalInt(oTarg, sVariable);
	int nNewValue;
	
	if (GetStringLeft(sChange, 1) == "=")
	{
		string s = GetStringRight(sChange, GetStringLength(sChange) - 1);
		nNewValue = StringToInt(s);
	}		
	
	else nNewValue = CalcNewIntValue(nOldValue, sChange);

	SetLocalInt(oTarg, sVariable, nNewValue);
}
2 Likes

@travus

That looks better. :slight_smile: (Will test, but looks good to me. UPDATE: As suspected, works fine!)

I guess this will end up a new campaign script then. :slight_smile:

In this case, your fix to the official script is better than having to use a workaround script.

Thanks!

1 Like