Aller au contenu

Photo

Local variable problems


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

#1
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
Hey,

I'm trying to set a persistent local value and use it throughout my script(s).

What I've done:

- Created var_myname.gda m2da file containing one value "NP_ITEM_LYRIUMADDICT", 0.
- I placed the m2da file in my addins/myaddin/core/override folder
- Restarted the Toolset and set var_myname as the variables file
- Edited a custom script with this code:
int nTotal = GetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT");
if(nTotal < 5)
{
    nTotal++;
    SetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT",nTotal);
    DisplayFloatyMessage (stEvent.oCaster,"Current Potion Count: " + 
      IntToString(nTotal),FLOATY_MESSAGE,16777215,10.0f);
}
else
{
    SetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT",0);
}

I think I'm misunderstanding the way these variables work because my floaty always comes back empty, as in "Current Potion Count: ()".

According to the function description, when retrieving the variable, if the variable isn't set or an error is returned, the value defaults to 0. So how comes my nTotal is still empty? I tried it with drinking multiple potions (as that's when this code triggers) but each time it returns an empty value...

Modifié par Joshua Raven, 26 novembre 2009 - 03:41 .


#2
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
Looking at this script, I'm starting to wonder if GetLocalInt is the right way to get the m2da variable?

I guess the below code would work? But how would I retrieve a value in the m2da file and placing it in an integer/string/etc without having to attach it to an object?

int nTotal = GetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT");

if(!nTotal)
{
    SetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT",0);
    int nTotal = GetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT");

}

if(nTotal < 5)
{
    nTotal++;
    SetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT",nTotal);
    DisplayFloatyMessage (stEvent.oCaster,"Current Potion Count: " + 
      IntToString(nTotal),FLOATY_MESSAGE,16777215,10.0f);
}
else
{
    SetLocalInt(stEvent.oCaster,"NP_ITEMS_LYRIUMADDICT",0);
}

EDIT:
Well, the second script at least returns 1 instead of NULL. But it won't increase the number after a second potion, which to me looks like the SetLocalInt isn't saving the variable correctly and the next time the script runs, !nTotal will be TRUE because GetLocalInt failed to return the integer, resulting in a reset of the variable to 0, why?

Modifié par Joshua Raven, 26 novembre 2009 - 03:42 .


#3
Craig Graff

Craig Graff
  • Members
  • 608 messages
It looks like you set up a variable table on the module and then are trying to use that table to set values on creatures (stEvent.oCaster). It doesn't work that way - you need to do one of the following:



-replace var_creature.xls with a version that also contains your variable

-add a separate module variable for each party member and increment your variable on the module

-apply an effect to the caster and increment an effect integer (this is likely the best method, but is a bit more complicated)



#4
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
Thanks Craig,

That makes sense. Can the var_creature - instead of being replaced - also include m2da additions? Just tried this, it doesn't work as I expected it would, guess I need to find me some more documentation on this subject. And if so, should I just put the m2da in the override dir without loading it in the module variable table, after which I can retrieve the variables through the above script?

And just as a follow up question about your second solution (though that probably is the "worst" of the three), how would one set and/or get a module variable after it's created in the var_module (m)2da? The SetLocalInt and GetLocalInt variables require an object to place/retrieve the variable on/from?

Your last solution certainly *sounds* like the most complicated of the three, I'll go read in on effects and how they work but for now I'd like to try either your first (preferably, if m2da's work) or second method.

Modifié par Joshua Raven, 26 novembre 2009 - 04:16 .


#5
AND04

AND04
  • Members
  • 154 messages

Joshua Raven wrote...

Thanks Craig,

That makes sense. Can the var_creature - instead of being replaced - also include m2da additions? Just tried this, it doesn't work as I expected it would, guess I need to find me some more documentation on this subject. And if so, should I just put the m2da in the override dir without loading it in the module variable table, after which I can retrieve the variables through the above script?

And just as a follow up question about your second solution (though that probably is the "worst" of the three), how would one set and/or get a module variable after it's created in the var_module (m)2da? The SetLocalInt and GetLocalInt variables require an object to place/retrieve the variable on/from?

Your last solution certainly *sounds* like the most complicated of the three, I'll go read in on effects and how they work but for now I'd like to try either your first (preferably, if m2da's work) or second method.


you can use GetModule() to get the Object

#6
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
THanks  AND04, I'll probably not be using that technique though. As I understand it, I'd have to build in checks for which party member is drinking the item and then set the VAR associated with that member, it would be easier to use the same VAR which affects only the current target and keeps that value on him/her, as the var_creature VARS do if I'm not mistaken.

Also, since you already mastered this well before I tried to mess with it (I just read your reply on the other post about this subject). If I wanted to use the technique which adds a new variable to a var_creature_my.gda M2DA. How would this work?

I tried:

- Create the M2DA by removing all lines and added "NP_ITEMS_LYRIUMADDICT", 0
- Moved the gda file to the override directory
- Used the script as written in comment 2.

It still keeps returning 0? I'm not quite getting how I can retrieve/save the variable here, even if I'm now supposed to be using the correct var_creature_my M2DA?...

Modifié par Joshua Raven, 26 novembre 2009 - 04:42 .


#7
AND04

AND04
  • Members
  • 154 messages
the problem in this case is - that the creatures aka your Followers still have the other var-2DA attached - and note afaik its a 2DA not a M2DA so not extentable --> you'd need to override the whole 2DA (use the same name) - that however means only 1 mod that does that can "exist" at a time

Modifié par AND04, 26 novembre 2009 - 04:55 .


#8
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
I see. That certainly rules out that solution. Thanks though. Guess the only solution left is the use of effects. Never thought it would be this hard to simply set a global variable.

Or does anyone know another way to keep track of the number of potions someone drank, and being able to reset that number after a certain condition?

Modifié par Joshua Raven, 26 novembre 2009 - 05:42 .


#9
elys

elys
  • Members
  • 458 messages
If you don't want to use effects, you may wanna try to use Plot Actions.

I've noticed the existence of SetPlotActionCount and GetPlotActionCount functions in the toolset script help.
plotactiondefines is a M2DA (sheet found in plotactions.xls), and so can be extended easily.

But I've found no vanilla script shipped with the toolset that makes use of them. So maybe they are unused or even not really implemented.

But it might be worth a try?

Modifié par elys, 26 novembre 2009 - 06:07 .


#10
Craig Graff

Craig Graff
  • Members
  • 608 messages

elys wrote...

If you don't want to use effects, you may wanna try to use Plot Actions.


That isn't likely what you think it is - it's tied into the GUI that you see in plots like the fade and the climax (the transformations and the armies).

#11
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
Well, I come from a webdeveloper world (php/asp.net/databases/etc) so a lot of things with C++ feel familiar while others don't. This is one of those things where I'm at a total loss for the moment. So there is no global variable setting? A "Session" variable as it where?



I've been reading up on the effects technique and I can see how it works in this case, but haven't figured it out yet and I wonder if there haven't been tons of situations during development of DA:O where you needed to save certain variables for a character and retrieve those values during later stages of a level or somewhere else?



Too bad the var_creature is not m2da compatible, would've been very easy that way.

#12
Craig Graff

Craig Graff
  • Members
  • 608 messages
Another thing you could try is adding a creature property in CreatureProperties.xls

#13
Nodrak

Nodrak
  • Members
  • 144 messages
Every creature, and actually, every designer resource has 3 'counter slots' in their default variable 2da, of type int.  The creature ones are:
CREATURE_COUNTER_1
CREATURE_COUNTER_2
CREATURE_COUNTER_3

These are generic basic counters to be used by modders afaik, though I am unsure if they are used in any specifics in the OC.

Modifié par Nodrak, 26 novembre 2009 - 11:43 .


#14
elys

elys
  • Members
  • 458 messages

Craig Graff wrote...
That isn't likely what you think it is - it's tied into the GUI that you see in plots like the fade and the climax (the transformations and the armies).


I just meant to eventually use it as an int container if it is possible without messing with the GUI, even if it's not its designed purpose.  Just a work around to store int values, with M2DA.

But anyway  I just realized Joshua Raven wants object variables, not global ones, so that would not help in this case Posted Image

Modifié par elys, 27 novembre 2009 - 01:14 .


#15
Sederien

Sederien
  • Members
  • 18 messages
Many mods that I am familar with in other games would work around this problem by adding a single item to the players inventory and using it to keep track of all the variables they wanted to use.



Is it possible to make a plot item that would serve as a container of sorts for your script variables?

#16
AND04

AND04
  • Members
  • 154 messages

Sederien wrote...

Many mods that I am familar with in other games would work around this problem by adding a single item to the players inventory and using it to keep track of all the variables they wanted to use.

Is it possible to make a plot item that would serve as a container of sorts for your script variables?


sure that would work - you'd need to create a new Var_something 2da and assign it to that item but sure.

#17
Joshua Raven

Joshua Raven
  • Members
  • 182 messages

Craig Graff wrote...

Another thing you could try is adding a creature property in CreatureProperties.xls


I'm looking at this solution right now (and change it to an effects solution later, when I get more grip on the scripting). A question that pops up while testing through;

I've got the value setting/getting working by creating a properties_np.gda m2da file with one line, which includes my property value. The problem I seem to be having is that the ID of the line NEEDS to be exactly one more than the last line of the original properties.gda.

This returns the current value:

properties_np.gda m2da value:
ID    Stat               Type      Min  Max
[b]60    lyrium_addiction   SIMPLE    4    12[/b]

float fTest = GetCreatureProperty(stEvent.oCaster, 60);
DisplayFloatyMessage(stEvent.oCaster, ToString(fTest));

// Returns 4.0000

While this fails:
properties_np.gda m2da value:
ID    Stat               Type      Min  Max
[b]123   lyrium_addiction   SIMPLE    4    12[/b]

float fTest = GetCreatureProperty(stEvent.oCaster, 123);
DisplayFloatyMessage(stEvent.oCaster, ToString(fTest));

// Returns 0.0000

If this is a requirement for the ID to be exactly the next in line, then how can I ever make sure my creature property stays unique and won't be overwritten by a different mod, adding their own creature properties?

Or am I missing something here? :unsure:

Modifié par Joshua Raven, 01 décembre 2009 - 08:14 .


#18
Phaenan

Phaenan
  • Members
  • 315 messages
While I didn't try to expand the properties tables itself, no other table forced me to use that kind of IDs. On the contrary I'm usually using IDs quite far away (like half a million above the last official index) and that works.
So, maybe that specific table is special, but I'd say you're maybe missing something somewhere. I never actually used very low ID values, such as your 123, so maybe you should try adding a few 0. Maybe some IDs reserved in M2DA, or something... :o

Modifié par Phaenan, 01 décembre 2009 - 08:24 .


#19
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
I actually tried 11014 at first, but figured the table might dislike these high numbers ;) I'll go ahead and give it another shot...

60... Yes
123... No
11014... No
10181001... No

Modifié par Joshua Raven, 01 décembre 2009 - 08:30 .


#20
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
Well here is some more testing:

m2da:
// overriding the original properties.gda value
59	Electricity_Damage_Bonus	ATTRIBUTE	[b]1[/b]	30 
// new value directly following last properties.gda ID
60	lyrium_addiction	SIMPLE	[b]2[/b]	10
// new value with random ID
10181001	test_item001	SIMPLE	[b]3[/b]	4


script:

float fTest1 = GetCreatureProperty(stEvent.oCaster, 59);
float fTest2 = GetCreatureProperty(stEvent.oCaster, 60);
float fTest3 = GetCreatureProperty(stEvent.oCaster, 10181001);

DisplayFloatyMessage(stEvent.oCaster, ToString(fTest1));
DisplayFloatyMessage(stEvent.oCaster, ToString(fTest2));
DisplayFloatyMessage(stEvent.oCaster, ToString(fTest3));

Returned:
fTest1: 1
fTest2: 2
fTest3: 0

:o

Modifié par Joshua Raven, 01 décembre 2009 - 08:43 .


#21
Phaenan

Phaenan
  • Members
  • 315 messages
Can you see your M2DA entries if you query the table directly ? Cause that remember me the issue with the BITM table m2da. (ignored by the engine yet still in the merged tables)
Something like :
DisplayFloatyMessage(GetM2DAInt(-1, "ID", 10181001, "properties_np"));

(didn't use the TABLE_* constant 'cause I'm not sure which one it is in this case)

Modifié par Phaenan, 01 décembre 2009 - 08:51 .


#22
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
You are correct:

float fAddictLvl = GetCreatureProperty(stEvent.oCaster, 10181001);

DisplayFloatyMessage(stEvent.oCaster, ToString(fAddictLvl));
DisplayFloatyMessage(stEvent.oCaster, ToString(GetM2DAInt(-1, "ID", 10181001, "properties_np_items")));
Returned 0 (should be 1) and 10181001

So the row is integrated in the 2da, it just can't be retrieved by the GetCreatureProperty function? Next up is to test if adding ID 60, 61, 62 will all result in positive returns.

EDIT:
That's a YES. using subsequent ID values (starting at 60, increments of 1) will function correctly in the game, using anything but the next ID in line will break the 2da from that ID onwards.

Here's to hoping a dev sees this in time to include in the next game/toolset patch

Modifié par Joshua Raven, 01 décembre 2009 - 09:09 .


#23
Craig Graff

Craig Graff
  • Members
  • 608 messages
Some 2das work sequentially. It would seem properties.xls is one of them.

#24
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
Hmm. Is there a reason for this? The 2da is marked as "m2da ready" in the 2da_base xls but limiting new entries to be sequentially kind of nullifies the feature of extending the 2da, and almost completely locks off this xls for proper modding, wouldn't you say?

#25
Craig Graff

Craig Graff
  • Members
  • 608 messages
This isn't a 2da I've worked with directly before. It may be that it's functionality could be changed, but it is also quite possible that the game needs to be able to check through all of the properties sequentially and it is intended to keep the number small.



Though it does make it significantly more difficult to ensure that there aren't conflicts, it is certainly not impossible.



By the way, in the above post when trying to look up the table values directly the table name should be "Properties".