bwins95 Posted November 9, 2013 Share Posted November 9, 2013 I've got two scripts that partially work. First scn aaaaGlowingItemsref rCurrentRefBegin OnEquip player;---------;Armor;---------set rCurrentRef to GetFirstRef 24 1 0Label 1if IsFormValid rCurrentRefif aaaaGlowingItemsArmor == 1rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenelseif aaaaGlowingItemsArmor ==0rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 1endifendif;----------------;Weapons;----------------set rCurrentRef to GetFirstRef 40 1 0Label 2if IsFormValid rCurrentRefrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 2endif;----------;Books;----------set rCurrentRef to GetFirstRef 25 1 0Label 3if IsFormValid rCurrentRefrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 3endif;-------------;Clothing;--------------set rCurrentRef to GetFirstRef 26 1 0Label 4if IsFormValid rCurrentRefrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 4endif;------------------;Containers;----------------set rCurrentRef to GetFirstRef 27 1 0Label 5if IsFormValid rCurrentRefrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 5endif;-----------------;Ingredient;------------------set rCurrentRef to GetFirstRef 29 1 0Label 6if IsFormValid rCurrentRefrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 6endif;-------;Misc;--------set rCurrentRef to GetFirstRef 31 1 0Label 7if IsFormValid rCurrentRefrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 7endif;----------;Ammo;----------set rCurrentRef to GetFirstRef 41 1 0Label 8if IsFormValid rCurrentRefrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 8endifEnd this one should be applying a shader to all the items that it finds, but when I added the global variable it only applies the shader to a single item of the type. Second scn aaaaGlowingItemsMCMshort iMastershort iMouseovershort iOptionshort iTempfloat fTempfloat fValuereference rListBegin GameModeif GetGameRestartedif IsModLoaded "The Mod Configuration Menu.esp"set iMaster to GetModIndex "The Mod Configuration Menu.esp"set rList to BuildRef iMaster 2790ListAddForm rList aaaaGlowingItemsMiscItemendifendifEndBegin MenuMode 1013if IsModLoaded "The Mod Configuration Menu.esp"elseReturnendifif GetUIFloat "StartMenu/MCM/_ActiveMod" == GetModIndex "Glowing items V2menu prep.esp"set iOption to GetUIFloat "StartMenu/MCM/_ActiveOption"set fValue to GetUIFloat "StartMenu/MCM/_Value";-----------------------------------------------------------------------------------------------------------;===========================================================================================================if GetUIFloat "StartMenu/MCM/_Reset" ;1 - RESETSetUIFloat "StartMenu/MCM/_Reset" 0SetUIFloat "StartMenu/MCM/*:1/_columns" 2set itemp to aaaaGlowingItemsArmor == 1SetUIFloat "StartMenu/MCM/*:1/*:4/_enable" 1SetUIString "StartMenu/MCM/*:1/*:4/_title" "Turn glowing armor on"SetUIFloat "StartMenu/MCM/*:1/*:4/_type" 4SetUIFloat "StartMenu/MCM/*:1/*:4/_value" aaaaGlowingItemsArmor;-----------------------------------------------------------------------------------------------------------;===========================================================================================================elseif GetUIFloat "StartMenu/MCM/_Default" ;2 - DEFAULTSetUIFloat "StartMenu/MCM/_Default" 0SetUIFloat "StartMenu/MCM/_Reset" 1set aaaaGlowingItemsArmor to 0;-----------------------------------------------------------------------------------------------------------;===========================================================================================================elseif GetUIFloat "StartMenu/MCM/_NewValue" ;3 - NEW VALUESetUIFloat "StartMenu/MCM/_NewValue" 0SetUIFloat "StartMenu/MCM/_Reset" 1if iOption == 1set aaaaGlowingItemsArmor to 1elseif ioption == 2set aaaaGlowingItemsArmor to 0endifendif;-----------------------------------------------------------------------------------------------------------;===========================================================================================================if iMouseover != GetUIFloat "StartMenu/MCM/*:1/_optionID" ;7 - MOUSE-OVERset iMouseover to GetUIFloat "StartMenu/MCM/*:1/_optionID"if iMouseoverSetUIFloat "StartMenu/MCM/MCM_Info/visible" 1if iMouseover == 1SetUIString "StartMenu/MCM/MCM_Info/string" "Makes armor glow"elseSetUIFloat "StartMenu/MCM/MCM_Info/visible" 0endifelseSetUIFloat "StartMenu/MCM/MCM_Info/visible" 0endifendifendifEnd This mcm script only switches to on. I can't change it back to off. I have a feeling it's something small hat I'm overlooking. How do I add more items to the mcm page? I need to add more on/off switches. Link to comment Share on other sites More sharing options...
Jojash Posted November 9, 2013 Share Posted November 9, 2013 (edited) For your first script, why are you using IsFormValid? From a quick look on the wiki it looks as thought this would stop your shader from being applied to anything that wasn't a persistent reference, which is most things. As for your second, these lines: if iOption == 1 set aaaaGlowingItemsArmor to 1 elseif ioption == 2 set aaaaGlowingItemsArmor to 0 endifwould imply that you've set up two buttons, one to turn off the effect and one to turn it on. However, you've only made one entry, therefore, iOption will never be 2. It should read: if iOption == 1 if aaaaGlowingItemsArmor set aaaaGlowingItemsArmor to 0 else set aaaaGlowingItemsArmor to 1 endif endif I'd recommend reading the MCM guide, it's very helpful. :smile: Edited November 9, 2013 by Jojash Link to comment Share on other sites More sharing options...
jazzisparis Posted November 9, 2013 Share Posted November 9, 2013 (edited) First:I suppose loops and/or REF walking may not work properly when inside an OnEquip block. Try moving it to a GameMode block: scn aaaaGlowingItems short bScan ref rCurrentRef begin OnEquip player set bScan to 1 end begin GameMode if bScan set bScan to 0 (Move everything from the OnEquip block here) endif end Second:You only have a single ON/OFF setting there, and its index is 4, so it should be: if iOption == 4 set aaaaGlowingItemsArmor to fValue endif Edited November 9, 2013 by jazzisparis Link to comment Share on other sites More sharing options...
jazzisparis Posted November 9, 2013 Share Posted November 9, 2013 For your first script, why are you using IsFormValid? Jojash is right. It is very possible this is what's causing the problem. Try replacing it with if rCurrentRef Link to comment Share on other sites More sharing options...
rickerhk Posted November 9, 2013 Share Posted November 9, 2013 isFormValid checks to see if the form is loaded into memory. This is helpful in cases where you've set a ref variable to a temporary ref or a placeatme in the game world and you want to come back to it later - well, the game might have unloaded it by that time, so you check to see if the ref is still valid form before doing anything with it. Not for Refwalks. Link to comment Share on other sites More sharing options...
bwins95 Posted November 9, 2013 Author Share Posted November 9, 2013 (edited) First:I suppose loops and/or REF walking may not work properly when inside an OnEquip block. Try moving it to a GameMode block: scn aaaaGlowingItems short bScan ref rCurrentRef begin OnEquip player set bScan to 1 end begin GameMode if bScan set bScan to 0 (Move everything from the OnEquip block here) endif end Second:You only have a single ON/OFF setting there, and its index is 4, so it should be: if iOption == 4 set aaaaGlowingItemsArmor to fValue endThank you. you saved me a few days of reading for the switch. The ref walking seems to work the same with a direct onequip or gamemode. the first global variable in the armor part only targets a single item. the second global variable in the armor part hits everything that it should. Edited November 9, 2013 by bwins95 Link to comment Share on other sites More sharing options...
Gribbleshnibit8 Posted November 10, 2013 Share Posted November 10, 2013 For the record, and to extend the explanation, rickerhk is correct. IsFormValid is a perfectly valid function to use there, though as far as I know doing a simple if <item> works almost the same. IsFormValid does give a more consistent feel to scripts, and keeps them more self documenting, so I use it. It is also valid to use on any form in every circumstance I've encountered. I use it for list walking of both static and dynamic lists (detects the end of the list just fine). I use it in other places too, and have found that other types of checks can actually cause a crash where IsFormValid will not. Another point to consider, for anyone else referencing in the future is that if your script is crashing for some unknown reason, and you are doing something with potentially non-persistent refs, throw an IsFormValid check in just to make sure. Link to comment Share on other sites More sharing options...
bwins95 Posted November 10, 2013 Author Share Posted November 10, 2013 Each time I try this it keeps applying the red shader to the exact same item until i pick up the item then it applies it to a different item. it is still a single item instead of all the armor in the cell. I have tracked it down to this. if aaaaGlowingItemsArmor == 1rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed I tried both if rcurrentref and if isvalidform and the both give the same result. Link to comment Share on other sites More sharing options...
bwins95 Posted November 10, 2013 Author Share Posted November 10, 2013 I figured it out. the problem was a misplaced end if. set rCurrentRef to GetFirstRef 24 1 0Label 1if IsFormValid rCurrentRefif aaaaGlowingItemsArmor == 1rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRedrCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreenelseif aaaaGlowingItemsArmor ==0rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlueset rCurrentRef to Pencil01set rCurrentRef to GetNextRefGoTo 1endifendif this part the two end if's at the bottom is wrong. one of them should have been after the second global variable. Link to comment Share on other sites More sharing options...
Recommended Posts