Array command questions

Post » Thu Feb 17, 2011 4:46 am

		If eval (ar_Find spell aaBirthsignNPCQ.Birthsign)!= -99999.0;aaBirthsignNPCQ.Birthsign is an array with the birthsign spells, initialized in another script. Maybe I should carry it over here as another array_var?

Pulled directly from the post, it looks like the line is bad - there should be a space between ")" and "!=". Also try a space between the number and the comment (eval can be tricky, but I think it can pick up on comments and ignore them). Hmm.... maybe it's also running it as if (eval arFind...) != -99999.0? Try some more parenthesis ((arFind...) != -99999.0). Final test if none of that works, print out the return print (ar_Find spell aaBirthsignNPCQ.Birthsign)
User avatar
Madison Poo
 
Posts: 3414
Joined: Wed Oct 24, 2007 9:09 pm

Post » Thu Feb 17, 2011 7:11 am

As haama mentioned the parenthesis, I remembered that the compiler sometimes does not like negative numbers without parenthesis. So I tested it . . .

But the problem must be elsewhere.

This works fine for me (returns Found for the apple and not Found for the player ref):
let arr := ar_construct maplet arr[3] := applelet reff := appleIf eval (ar_Find reff arr) != -99999.0    Printc  "* * Found * *"else    Printc  "* * Not Found * *"EndIflet reff := playerrefIf eval (ar_Find reff arr) != -99999.0    Printc  "* * Found * *"else    Printc  "* * Not Found * *"EndIf

User avatar
Leilene Nessel
 
Posts: 3428
Joined: Sun Apr 15, 2007 2:11 am

Post » Thu Feb 17, 2011 4:10 am

Thanks for the replies, and yes, the problem is not in ar_Find, so I'm trusting the -99999 stuff now. The real problem is I'm going a bit over my head with the mod I'm trying to make (birthsign spells to NPCs? And with security system to ensure they get added and removed safely? Preposterous!!!)

It has things like a gigantic array of arrays with all the spells from the 13 birthsigns that i don't even know how to handle, an array for exceptions (like shadowscale argonians from Ruined Tail's Tale) that uses GetFormFromMod and I'm failing miserably at handling: I try to set elements of the array to a GetFormFromMod six digit formId, and then use ar_Find to check if an actor is inside that array, but it always returns -99999. Does GetFormFromMod store variables as complete, mod-indexed formIDs or as EditorID strings? Does ar_Find check for formID numbers or for editorID strings?
User avatar
Andres Lechuga
 
Posts: 3406
Joined: Sun Aug 12, 2007 8:47 pm

Post » Thu Feb 17, 2011 1:31 am

I've never actually used GetFormFromMod, but what I understand from the docs is that it will look for the object/reference from the given mod that matches the provided 6-digit string. If found, it prepends the current mod index and returns a reference/FormID.

Since the mod index may change from run to run, I suppose you are rebuilding the array every game load.

And, again, since the mod index may change from run to run, you need to provide ar_find with a perfect matched mod-indexed formID for that run.
User avatar
Del Arte
 
Posts: 3543
Joined: Tue Aug 01, 2006 8:40 pm

Post » Wed Feb 16, 2011 8:37 pm

Yes, I rebuild the arrays on GetGameLoaded. So I have to retrieve the mod index (GetModIndex) as well, and add it to the array element? With sv_Construct? Or GetFormFromMod should already provide the full 8 digit mod indexed formID?
Or that I have to use 8 digit formIDs as arguments to search for in ar_Find, instead of variables?
Well, I really should get used to use Print to check all of this. I have ConScribe after all...
User avatar
Tom
 
Posts: 3463
Joined: Sun Aug 05, 2007 7:39 pm

Post » Wed Feb 16, 2011 7:06 pm

GetFormFromMod returns a FormID that can be stored in a ref var

Example:
Suppose you want to build an array with all known fruits in the game and let's say Oblivion has only Apples and Pears.
And suppose you know a mod AAA that has an orange object with FormID xx001122.

You would build it like this:
array_var arFruitsref reffLet arFruits := ar_construct arrayLet arFruits[0] := AppleLet arFruits[1] := PearLet arFruits[2] := GetFormFromMod "AAA" "001122"   ;<< the alien orange;=== or, even better ===Let reff := GetFormFromMod "AAA" "001122"If isformvalid reff     Let arFruits[2] := reffEndif


Now, if you want to know if there is any fruit around:
set reff to getfirstref  25 0  ;;;  25 = Ingredientwhile reff    if eval (ar_Find reff.getbaseobject arFruits) != -99999.0        Printc  "* * Found a fruit: %n  * *" reff    endif    set reff to getnextrefloop


(not tested, but i hope it hepls)
User avatar
Nina Mccormick
 
Posts: 3507
Joined: Mon Sep 18, 2006 5:38 pm

Post » Wed Feb 16, 2011 6:31 pm

It does help. GetBaseObject sounds like the kind of thing my ar_Find check was missing to actually work! Ok, I'm trying for the no 53 time, thanks for the help.

Wow, I made it. This is the most abstract thing I've done in my life!
User avatar
Richard Thompson
 
Posts: 3302
Joined: Mon Jun 04, 2007 3:49 am

Post » Thu Feb 17, 2011 12:36 am

Been a while since I've done this, but most of it is coming back. One question, though, that doesn't seem to be touched here - if you use eval on a non-existent key, does it balk?

I have several leveled lists and want to store information for each: an alternative list, Ignore Flag (use original instead of alternative list), List Before (number of items in the list the last time I checked, so I skip if they match), Auto Add items (items to add to alternative list, from original list), and further down the line Manual Add items, Manual Remove items. IgnoreFlag isn't really necessary, unless it's set to 1. So I'd like to check it with if eval CoblDropLists[Key]["IgnoreFlag"] - if the "IgnoreFlag" key hasn't been set up, will it simply return 0, 1, or throw errors?
User avatar
Andrew
 
Posts: 3521
Joined: Tue May 08, 2007 1:44 am

Post » Wed Feb 16, 2011 5:56 pm

Throws an error.

You have to use ar_HasKey first: if eval ar_HasKey CoblDropLists[Key] "IgnoreFlag"

What I do when there is a known (not very large) list of possible keys, is to always initialize the array with all those keys, so I don't have to check for their presence all over the place.

In this particular case, being a flag, you could use the presence/absence of the key as the condition, ignoring the corresponding value.
User avatar
Krista Belle Davis
 
Posts: 3405
Joined: Tue Aug 22, 2006 3:00 am

Post » Wed Feb 16, 2011 9:00 pm

Throws an error.

You have to use ar_HasKey first: if eval ar_HasKey CoblDropLists[Key] "IgnoreFlag"

What I do when there is a known (not very large) list of possible keys, is to always initialize the array with all those keys, so I don't have to check for their presence all over the place.

In this particular case, being a flag, you could use the presence/absence of the key as the condition, ignoring the corresponding value.

Aha! Missed that - good suggestion, I don't even need to set the field.
User avatar
Auguste Bartholdi
 
Posts: 3521
Joined: Tue Jun 13, 2006 11:20 am

Post » Thu Feb 17, 2011 7:11 am

How do you add things to an array through a script? I'm trying with a function script, but no matter if I use ar_Append or ar_Insert, I can't achieve it.

The array gets initialized through let myarray := ar_Construct Array in myquest script. Then it RunBatchScript an .ini. I know the ini is indeed initialized because I get the variables in it set correct afterwards.

The function is
scn myfunctionref exceptionarray_var spellsbegin Function {exception}If IsFormValid exception	If exception.GetObjectType == 35		ar_Append myquest.myarray exception	ElseIf exception.GetObjectType == 17		let spells := (GetBirthsignSpells exception)		ar_Append myquest.myarray spells	EndIfElse	PrintD "Unvalid form"EndIfEnd

The quest has a stage 10 and repeated stages enabled, and the stage runs "Call myfunction myquest.custom", where custom is a ref variable in myquest.

So I have an ini with lines like:
set myquest.custom to (GetFormFromMod "Oblivion.esm" 01FD91)SetStage myquest 10

That would be the Apprentice birthsign for example, but using ar_DumpID myquest.myarray in the console shows the array remains empty, and I don't get the message "Unvalid form" nor any other message I try placing in the function script.
User avatar
Eve Booker
 
Posts: 3300
Joined: Thu Jul 20, 2006 7:53 pm

Post » Wed Feb 16, 2011 8:57 pm

0001FD91 is a BirthSign, therefore a Base Object, therefore the syntax must be "ElseIf GetObjectType exception == 17"

But, sprinkle a few more PrintD there, so you can see how the execution navigated thru the function code.
User avatar
Claire Vaux
 
Posts: 3485
Joined: Sun Aug 06, 2006 6:56 am

Post » Wed Feb 16, 2011 8:54 pm

0001FD91 is a BirthSign, therefore a Base Object, therefore the syntax must be "ElseIf GetObjectType exception == 17"

But, sprinkle a few more PrintD there, so you can see how the execution navigated thru the function code.

You saved my modding [censored] again, thank you very much. Most of my mistakes have been from mixing references and base objects. Now I finally know how to tell them apart.
User avatar
Catherine Harte
 
Posts: 3379
Joined: Sat Aug 26, 2006 12:58 pm

Previous

Return to IV - Oblivion