Global Variables in a Mod
#1
Posté 20 juillet 2011 - 06:18
#2
Posté 20 juillet 2011 - 06:48
but this variable is not global totally thorought all scripts, only in one script. If you call it in second Im pretty sure its lost its value already so in the end its not much use except of something like custom GetFirst/NextSomething function where you need to count it somehow, using local variable on some object is one variant using global variable second one. But be carefull with name, it may happen that you reuse the global variable name inside void main(){}, then bad things can happen.
#3
Posté 20 juillet 2011 - 07:18
#4
Posté 20 juillet 2011 - 08:36
Ironically, In order to get something that resembles a Global variable, you need to use what NWN calls a Local Varaiable. What NWN calls a Local Varaiable is a Key/Value list that is part of many of the Objects structures in the game, So to get your Global Var you will need to attach it to an Object as a Local var to that Object. Of cource the scope(Life Time) of the var will not exceed the life time of the Object you attach it to.
Look at:
Local Variables Functions
Looking mostly at the Get/SetLocal* functions.
#5
Posté 20 juillet 2011 - 09:29
L8 - thanx - aSetPLocalInt looks promising.
#6
Posté 21 juillet 2011 - 12:18
#7
Posté 21 juillet 2011 - 12:30
#8
Posté 21 juillet 2011 - 01:17
void main()
{
object oPC = GetPCSpeaker();
object oDBItem = GetItemPossessedBy(oPC, "Tag of DB Item here");
int iReputation = GetLocalInt(oDBItem, "MY_REPUTATION");
SetLocalInt(oDBItem, "MY_REPUTATION", iReputation + 10);
}
It checks the player for an item, then checks that item for an integer called "MY_REPUTATION", and then sets whatever that number is + 10. You can of course call the integer whatever you want and change the +10 to whatever you want. You might want to set a reputation int on the NPC the player is talking to. Then this script could just check for that integer and add that instead of the +10. Then you would only need one script if NPC will be giving different amounts of reputation. This can also be altered to add the reputation points to all of the players faction members as well.
Hope it helps. Good luck.
Modifié par GhostOfGod, 21 juillet 2011 - 01:21 .
#9
Posté 21 juillet 2011 - 03:42
Groove Widdit wrote...
What about adding a variable in the dialogue editor?
That would be more like how you add it, compared to where you put it. If your gonna go with the db or nodrop item idea you may want to consider the different groups in your mod may have different rep ratings toward the pc. The pc may have a steriling rep with the knights of goodly goodness, but be hated intensly by the dastardly devils of bewilderment. So you could in effect have several rep ratings with various groups, instead of one overall rep for a pc.
Modifié par Baragg, 21 juillet 2011 - 03:44 .
#10
Posté 21 juillet 2011 - 05:35
Thanks God. I'll try it.
#11
Posté 21 juillet 2011 - 01:43
Groove Widdit wrote...
Yeah I could have structures of arrays of specific rep elements - this could be getting into fractal calculi - or even Quantum Superposition (if, of course, the whole universe could be used as a data manipulation field).
Thanks God. I'll try it.
Lol.
If I am not mistaken NWScript does not have arrays.
#12
Posté 21 juillet 2011 - 08:04
Although a better solution in this case might just be to have a set number of sensibly named factions to lose or gain "_respect" with.
Modifié par _six, 21 juillet 2011 - 08:06 .
#13
Posté 21 juillet 2011 - 08:11
No arrays? Lame. Then you can never represent the entire universe in NWN, then. The basic unit of the universe is the string, with different frequency settings. On a certain level of VR you can take out the "virtual" - or go the other way: THe whole universe is virtual reality.
#14
Posté 22 juillet 2011 - 03:06
// Although not a real array, it can be used as one.
// Returns an integer value stored at index iIndex
int GetLocalArrayInt(object oObject, string sVarName, int iIndex);
// Although not a real array, it can be used as one.
// Returns a string value stored at index iIndex
string GetLocalArrayString(object oObject, string sVarName, int iIndex);
// Although not a real array, it can be used as one.
// Returns an object value stored at index iIndex
object GetLocalArrayObject(object oObject, string sVarName, int iIndex);
// Sets an integer value at index iIndex for a variable named sVarName
void SetLocalArrayInt(object oObject, string sVarName, int iIndex, int iValue);
// Sets a string value at index iIndex for a variable named sVarName
void SetLocalArrayString(object oObject, string sVarName, int iIndex, string sValue);
// Sets an object value at index iIndex for a variable named sVarName
void SetLocalArrayObject(object oObject, string sVarName, int iIndex, object oData);
// Deletes an integer value at index iIndex for a variable named sVarName
void DeleteLocalArrayInt(object oObject, string sVarName, int iIndex);
// Deletes a string value at index iIndex for a variable named sVarName
void DeleteLocalArrayString(object oObject, string sVarName, int iIndex);
// Deletes an object value at index iIndex for a variable named sVarName
void DeleteLocalArrayObject(object oObject, string sVarName, int iIndex);
int GetLocalArrayInt(object oObject, string sVarName, int iIndex)
{
return GetLocalInt(oObject, sVarName + IntToString(iIndex));
}
string GetLocalArrayString(object oObject, string sVarName, int iIndex)
{
return GetLocalString(oObject, sVarName + IntToString(iIndex));
}
object GetLocalArrayObject(object oObject, string sVarName, int iIndex)
{
return GetLocalObject(oObject, sVarName + IntToString(iIndex));
}
void SetLocalArrayInt(object oObject, string sVarName, int iIndex, int iValue)
{
SetLocalInt(oObject, sVarName + IntToString(iIndex), iValue);
}
void SetLocalArrayString(object oObject, string sVarName, int iIndex, string sValue)
{
SetLocalString(oObject, sVarName + IntToString(iIndex), sValue);
}
void SetLocalArrayObject(object oObject, string sVarName, int iIndex, object oData)
{
SetLocalObject(oObject, sVarName + IntToString(iIndex), oData);
}
void DeleteLocalArrayInt(object oObject, string sVarName, int iIndex)
{
DeleteLocalInt(oObject, sVarName + IntToString(iIndex));
}
void DeleteLocalArrayString(object oObject, string sVarName, int iIndex)
{
DeleteLocalString(oObject, sVarName + IntToString(iIndex));
}
void DeleteLocalArrayObject(object oObject, string sVarName, int iIndex)
{
DeleteLocalObject(oObject, sVarName + IntToString(iIndex));
}
#15
Posté 22 juillet 2011 - 04:16
zunath wrote...
The lazy man's array:
....
Or just use the one already in the base scripts. Even though it is not as expanded as the one Zunath posted.
#include "nw_o0_itemmaker"
GetLocalArrayInt
GetLocalArrayString
SetLocalArrayInt
SetLocalArrayString
#16
Posté 30 octobre 2013 - 07:27
#17
Posté 01 novembre 2013 - 01:29
#18
Posté 01 novembre 2013 - 08:09
#19
Posté 01 novembre 2013 - 10:22
why making workaround for something that works?
#20
Posté 01 novembre 2013 - 07:03
#21
Posté 02 novembre 2013 - 12:38
SetLocalInt(OBJECT_SELF, "beastalive", 1);
where OBJECT_SELF is the module.
Then in the OnDeath put:
SetLocalInt(GetModule(), "beastalive", 0);
You could also technically put
DeleteLocalInt(GetModule(), "beastalive");
since that effectively sets it to 0.
Then, in the conversation itself, you'd need something like
if (GetLocalInt(GetModule(), "beastalive")) return TRUE;
where "TRUE" indicates the beast is still alive since the int is still set to 1 (would be 0 if beast was dead).
Modifié par MagicalMaster, 02 novembre 2013 - 12:39 .
#22
Posté 02 novembre 2013 - 03:52
#23
Posté 02 novembre 2013 - 04:01
int StartingConditional()
{
return (GetLocalInt(GetModule(), "beastalive"));
}Simplified it a bit more.
#24
Posté 02 novembre 2013 - 04:57
you dont need to do that, instead check if she has been killed and set she has been killed on module like MM suggest by SetLocalInt(GetModule(),"blabla",TRUE); / GetLocalInt(GetModule(),"blabla")Groove Widdit wrote...
I'm trying to have a player only speak a line of dialogue only if a Beast is alive, so I'm trying to declare the variable iBeast in the OnModuleLoad and setting it to 1--the "alive" setting--and then setting to 0 in the critter's OnDeath script. Compiles, but doesn't work.
#25
Posté 02 novembre 2013 - 10:03
int StartingConditional()
{
if (GetLocalInt(GetModule(), "iBeast")) return TRUE;
return FALSE;
}





Retour en haut







