Xaranth Posted November 24, 2012 Share Posted November 24, 2012 (edited) So, I've spent most of the evening bashing my head against the wall trying to make list operations for my customized weapons work. Originally, I had them on object scripts in an onAdd block attached to each weapon. Which should have been fine, but.... The check statement NEVER evaluated right. I have a pistol with a FormID of DARC02WeapDARCPistol. I was running THIS condition, to avoid bloating the list... if (DARC02WeapDARCPistol.IsInList WeaponListRangedALL != 1) And I could NEVER get it to trigger right. I tried setting a variable and checking the variable instead. I tried adding another pair of ()'s around the IsInList call. No matter what I tried, that condition failed. I got around it by putting all my ListOps in a housekeeping quest but mein Gott, why is this not working? -X :wallbash: EDIT: I also checked the weapon ingame with the console, just to see if it had gotten on the list somehow. No dice. IsInList on the console returned 0.00 Edited November 24, 2012 by Xaranth Link to comment Share on other sites More sharing options...
viennacalling Posted November 25, 2012 Share Posted November 25, 2012 Since that conditional statement evaluated to the proper value when you tested it in the console, without being able to see the rest of the script I would infer that either 1) the if block is not being run at all or 2) it is being successfully run but whatever is inside the if block is not doing what you want. Link to comment Share on other sites More sharing options...
Xaranth Posted November 25, 2012 Author Share Posted November 25, 2012 Since that conditional statement evaluated to the proper value when you tested it in the console, without being able to see the rest of the script I would infer that either 1) the if block is not being run at all or 2) it is being successfully run but whatever is inside the if block is not doing what you want. The original script was attached to the weapon as an object script, thus: scn DARC02scptListOpsDARCPistol begin onAdd if (DARC02WeapDARCPistol.IsInList WeaponListRangedALL != 1) AddFormToFormList WeaponListRangedALL DARC02WeapDARCPistol ...And a bunch more AddFormToFormLists to make perks and challenges and such work with the pistol endIF end In the course of debugging, I made a debug version and attached it to an Activator: scn DARC02scptListOpsPistolDebug begin onActivate ShowMessage DARC07msgListOpsDebug01 if (DARC02WeapDARCPistol.IsInList WeaponListRangedALL != 1) AddFormToFormList WeaponListRangedALL DARC02WeapDARCPistol ...And a bunch more AddFormToFormLists to make perks and challenges and such work with the pistol ShowMessage DARC07msgListOpsDebug02 endIF end DARC07msgListOpsDebug01 was a non-box message, and showed up. DARC07msgListOpsDebug02 was a message box, and never did. For further testing still, I pulled the if statement and the endIf, and the Message02 DID show. So there's SOMETHING about the If statement that's not right, but stap me if I can figure it out. It doesn't REALLY matter, but I'd like to know why it never did work, so that I don't bollix something up in the future by making the same mistake again. Just bugger me though, if I can figure out what the mistake is. :wallbash: Link to comment Share on other sites More sharing options...
viennacalling Posted November 25, 2012 Share Posted November 25, 2012 (edited) I misread your initial post, I thought you were able to manually test the condition, set the weapon to be in the list, and test the condition again to verify that the item was in the list. The issue is that IsInList must be called against a reference and not a form object. Here is what I did as a test: scn dlc04ShovelSCRIPT ref myself begin onAdd if (myself.IsInList WeaponListRangedALL != 1) AddFormToFormList WeaponListRangedALL dlc04shovel ShowMessage AprilMartimerDead endIF end I added this to the dlc04shovel, placed one in the game and then picked it up. I got the AprilMartimerDead message, and then verified in console that IsInList returned 1.00. Edited November 25, 2012 by viennacalling Link to comment Share on other sites More sharing options...
Xaranth Posted November 25, 2012 Author Share Posted November 25, 2012 I misread your initial post, I thought you were able to manually test the condition, set the weapon to be in the list, and test the condition again to verify that the item was in the list. The issue is that IsInList must be called against a reference and not a form object. Here is what I did as a test: scn dlc04ShovelSCRIPT ref myself begin onAdd if (myself.IsInList WeaponListRangedALL != 1) AddFormToFormList WeaponListRangedALL dlc04shovel ShowMessage AprilMartimerDead endIF end I added this to the dlc04shovel, placed one in the game and then picked it up. I got the AprilMartimerDead message, and then verified in console that IsInList returned 1.00. .... OHHHHHH! Well, heck. That's just...evil. Thank you! Link to comment Share on other sites More sharing options...
viennacalling Posted November 25, 2012 Share Posted November 25, 2012 Oops, forgot a line when copying/pasting scn dlc04ShovelSCRIPT ref myself begin onAdd set myself to getself if (myself.IsInList WeaponListRangedALL != 1) AddFormToFormList WeaponListRangedALL dlc04shovel ShowMessage AprilMartimerDead endIF end But yeah, it took me several minutes starting at the Geck page for IsInList to understand what was going on. Link to comment Share on other sites More sharing options...
Xaranth Posted November 25, 2012 Author Share Posted November 25, 2012 Oops, forgot a line when copying/pastingBut yeah, it took me several minutes starting at the Geck page for IsInList to understand what was going on. Doesn't help that the documentation doesn't distinguish at all well between references and forms, either. :mad: And as a result I'd been treating them as near-indistinguishible. I ought to know better than that, but whatever. I know better now. See, this is why I ask these things even when I've successfully worked around the issue. The flaw in that script is symptomatic of a huge blind spot in the way I've been treating modding: "References and Forms are basically the same" and if I hadn't asked, I probably would have made a MUCH bigger and harder to find error much later on by treating them that way. So again, thanks. -X Link to comment Share on other sites More sharing options...
luthienanarion Posted November 25, 2012 Share Posted November 25, 2012 IsInList only works when called on references, and calling it on base objects will always return 0. If you need to see if a base object is in a list, you have to check NVSE's ListGetFormIndex function for a value gretaer than -1. Link to comment Share on other sites More sharing options...
Recommended Posts