Aller au contenu

Photo

Variable changes don't stick


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

#1
georage

georage
  • Members
  • 247 messages
I am clearly missing something.

Here is my problem.

I have set up my var_custom 2DA and it works, but how do you change the values of the variable declared there?

I want to keep track of the player's moral choices through a global int. I created a function that seems to work, but the EvilGood value does not stick! It always comes back as zero.

I call the function below from a trigger and it SHOULD make my PCEvilGood value keep adding up as I run back and forth across the trigger, but it does not.

void ModifyEvilGood(int x)
{
int iChange=x;
int iEvilGood = GetLocalInt(oMod,"PCEvilGood");
int iNewValue=iEvilGood+iChange;
SetLocalInt(oMod,"PCEvilGood",iNewValue);
if(iDebug!=0)
    DisplayFloatyMessage(oPC, "EvilGood - Change:"+IntToString(iChange)+" Total:"+IntToString(iNewValue), FLOATY_MESSAGE, 14654488, 6.0);
}

Modifié par georage, 07 décembre 2009 - 04:56 .


#2
georage

georage
  • Members
  • 247 messages
OK, I think I am making progress. Any variable that is a string can be modified as you would expect, but not ints.

I think the problem is the 2DA, which requires a default value column that is a string. Thus, strings work and ints do not.

How are others getting around this?

Here is how my 2DA is set up ... the string works, the int does not.
Posted Image

Here is the link to the wiki that describes how 2DAs are supposed to be set up ... you can see that it requires a default column set to type string.

http://social.biowar...s#Variable_2DAs 

#3
Craig Graff

Craig Graff
  • Members
  • 608 messages
Are you using Open Office, if so, try using the workaround at the bottom of the 2da wiki page.
social.bioware.com/wiki/datoolset/index.php/2DA

There is no general problem with assigning a default value for integers in the variable 2das (though I could always be wrong, the fact that we have had no problems with this in the main game makes it very unlikely).

Modifié par Craig Graff, 07 décembre 2009 - 08:47 .


#4
georage

georage
  • Members
  • 247 messages
I am using Excel. But thanks for the response.

I figured out the problem, apparently you must define objects within your function, or provide the object as a parameter of the function. I chose the latter.

This function works:
Usage: 
void main()
{
object oMod=GetModule();
ModifyEvilGood(5,oMod);
}

Function:
void ModifyEvilGood(int iChange, object oMod)
{
int iEvilGood = GetLocalInt(oMod,"PCEvilGood");
int iNewValue=iEvilGood+iChange;
SetLocalInt(oMod,"PCEvilGood",iNewValue);
if(iDebug!=0)
    DisplayFloatyMessage(oPC, "Evil/Good - Change:"+IntToString(iChange)+" Total:"+IntToString(iNewValue), FLOATY_MESSAGE, 14654488, 6.0);
}


This DOES NOT:
Usage: 
void main()
{
ModifyEvilGood(5);
}

Function:
//define global objects common to all functions
object oMod=GetModule();
// etc.

void ModifyEvilGood(int x)
{
int iChange=x;  
int iEvilGood = GetLocalInt(oMod,"PCEvilGood");
int iNewValue=iEvilGood+iChange;
SetLocalInt(oMod,"PCEvilGood",iNewValue);
if(iDebug!=0)
    DisplayFloatyMessage(oPC, "EvilGood - Change:"+IntToString(iChange)+" Total:"+IntToString(iNewValue), FLOATY_MESSAGE, 14654488, 6.0);
}

This seems to be a change from NWN, I think.

Modifié par georage, 07 décembre 2009 - 09:17 .


#5
Craig Graff

Craig Graff
  • Members
  • 608 messages
It wouldn't surprise me if there were issues with global variables, since we didn't use them at all. That said, I've used them a bit in tests and I didn't encounter the problem you found.

#6
Ashmaran

Ashmaran
  • Members
  • 52 messages
Why don't you use the already defined variables on the module: MODULE_COUNTER_1-3. I've used those and the value seems to stick fine. Since you're the only one setting variables on your module, and you know which is which it seems like a fair compromise.

#7
georage

georage
  • Members
  • 247 messages
Why?



Because I like to use variable names that make sense.




#8
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
In NWN, script global variables were not a problem until you tried to initialize them using a function call...that's when things got real iffy sometimes depending on what function you chose (stack underflow was one of the more common manifestations). Perhaps it's similar with DA. I found it safer to either stick with tramp data solutions or redefine a local variable in every function or wait to initialize it from within a local context rather than from the global scope.


#9
FalloutBoy

FalloutBoy
  • Members
  • 580 messages
I'm surprised the compiler even lets you try to call functions outside of a function scope. My guess is that they just get ignored. So oMod and oPC probably contain who knows what.

EDIT:
I bet if you changed it to this it would work also, though this is really bad style and you shouldn't use globals at all because as you can see, they are prone to errors.

object oMod;
object oPC;

main()
{
oMod = GetModule();
oPC = GetHero();   // is this is the right function call to get the PC?
ModifyGoodEvil(5);
}

Modifié par FalloutBoy, 08 décembre 2009 - 07:21 .


#10
Georg Zoeller

Georg Zoeller
  • Members
  • 188 messages
Do not use script global variables. On Dragon Age, Designers were explicitly forbidden to use global variables as they not a supported feature of the new scripting language.



Global variables need to be declared and used via the SetLocal* on the module

#11
Sunjammer

Sunjammer
  • Members
  • 925 messages

Axe_Murderer wrote...

In NWN, script global variables were not a problem ...

As I recall they were incredibly inefficient (in terms of their treatment on the stack) and of course declaring anything with more scope than required is almost always a Bad Thing™ ... 

Now if only BioWare would add the for(int i = 0; i < iMax; i++) syntax to dascript ...

:P

Modifié par Sunjammer, 08 décembre 2009 - 09:01 .