Taffer42 Posted September 19, 2018 Share Posted September 19, 2018 I've been really getting into modding my game lately. It seems every time I add a new mod, I end up tweaking it in some way, and each time I learn a little bit more. This time, however, I need to ask for help. (I should say I do have a coding background, but know nothing about the scripting language Skyrim uses). I have a mod that adds a spell to the player's known spells (happens automatically). I want to extend this to add an additional spell (so two). There is a function which adds the spell, which seems pretty straightforward (I'm just going to add a second game.GetPlayer().AddSpell(secondSpellToAdd, true) line in the function). However, there are two other functions that I think I need to edit. One looks like this: function Fragment_4()if myPlayerRef.HasSpell(spellToAdd as form) == 0 as BoolmyPlayerRef.AddSpell(spellToAdd, true)elseself.SetStage(15)endIfendFunction The second is almost identical to the first: function UnUpdate()if myPlayerRef.HasSpell(spellToAdd as form) == 0 as BoolmyPlayerRef.AddSpell(spellToAdd, true)elseself.UnregisterForUpdate()endIfendFunction Under normal circumstances, I think I know what to do, but the conditional statement is quite busy. So my question is, to add two spells, is this a viable function (given the above)? function UnUpdate()if (myPlayerRef.HasSpell(firstSpellToAdd as form) == 0 as Bool) || (myPlayerRef.HasSpell(firstSpellToAdd as form) == 0 as Bool)if myPlayerRef.HasSpell(firstSpellToAdd as form) == 0 as BoolmyPlayerRef.AddSpell(firstSpellToAdd, true)endIfif myPlayerRef.HasSpell(secondSpellToAdd as form) == 0 as BoolmyPlayerRef.AddSpell(secondSpellToAdd, true)endIfelseself.UnregisterForUpdate()endIfendFunction This looks right to me, but I don't know if I can do that much in a conditional with this programming language.I'm sure there are tools and such I could use to test these out, but I am just delving into scripting now, so my only testing is in-game. :( Any help is appreciated!Thank you for your time and consideration! Link to comment Share on other sites More sharing options...
SeraphimKensai Posted September 19, 2018 Share Posted September 19, 2018 To be honest I don't think you even need the conditional, as the game won't add a 2nd copy of an existing spell to the player, it seems that in that situation it just notes you have it and does nothing but keeps going in the script. I have a script which extends an object reference that adds about 100 spells to the player on equip, and removes them on unequip, all with no conditions. Link to comment Share on other sites More sharing options...
Taffer42 Posted September 19, 2018 Author Share Posted September 19, 2018 If I'm understanding you correctly, I don't need to check if the player has the spell, I just have to add it? If he doesn't have it, it gets added, and if he does have it, the command is ignored? function UnUpdate()myPlayerRef.AddSpell(firstSpellToAdd, true)myPlayerRef.AddSpell(secondSpellToAdd, true)self.UnregisterForUpdate()endFunction ...and that should essentially accomplish the same thing? Link to comment Share on other sites More sharing options...
SeraphimKensai Posted September 19, 2018 Share Posted September 19, 2018 Yes I believe how it works, or at least that's how its been working with my script as I don't have conditions on mine to check if I have the spell or not, and I can add the item, remove it, add it again without any issue. does it compile? give it a quick test and see if it works, you'll have to define the properties if you haven't. Link to comment Share on other sites More sharing options...
Taffer42 Posted September 19, 2018 Author Share Posted September 19, 2018 Okay, as far as testing goes...I know how to test to see if it works (I'll have the spells added)...and I know how to test if a quest is completed or at what stage the quest is at.... the real test here though, as I understand it, is that last function. If I understand what I read, that last function is stopping the script from running (the script has done what it was supposed to, now stop running so you're not using resources unnecessarily). How do I test in-game whether or not a script is running, or has finished running, or whatever I need to check? Is there a console command? "isscriptrunning <scriptname>" or something like that? That's the real test here, I think...because if I screw this up, the script will probably just keep running indefinitely. Link to comment Share on other sites More sharing options...
SeraphimKensai Posted September 19, 2018 Share Posted September 19, 2018 the easiest way that most of us use are debugging messages. You can stick in the middle of your function: Debug.MessageBox("Is my function running?")If you see the message box, and it will be pretty obvious as you'll have to click okay, then you know its running. Once you have your script running, you can take the messagebox out and recompile. Link to comment Share on other sites More sharing options...
cdcooley Posted September 20, 2018 Share Posted September 20, 2018 Based on that original you want to keep its tests, but simply add the second spell along with the first. function Fragment_4()if myPlayerRef.HasSpell(spellToAdd as form) == 0 as BoolmyPlayerRef.AddSpell(spellToAdd, true)myPlayerRef.AddSpell(secondSpellToAdd, true)elseself.SetStage(15)endIfendFunction The second is almost identical to the first: function UnUpdate()if myPlayerRef.HasSpell(spellToAdd as form) == 0 as BoolmyPlayerRef.AddSpell(spellToAdd, true)myPlayerRef.AddSpell(secondSpellToAdd, true)elseself.UnregisterForUpdate()endIfendFunction Link to comment Share on other sites More sharing options...
Deleted3897072User Posted September 20, 2018 Share Posted September 20, 2018 (edited) Just a styistic thing, instead of doing something like this myPlayerRef.HasSpell(spellToAdd as form) == 0 as Bool in a condition, Papyrus allows you to do simply !myPlayerRef.HasSpell(spellToAdd) which has the same result but is easier to read. If you don't like having negatives in conditions, you can swap the clauses so you have Function Fragment_4() If myPlayerRef.HasSpell(spellToAdd) SetStage(15) Else myPlayerRef.AddSpell(spellToAdd, true) myPlayerRef.AddSpell(secondSpellToAdd, true) EndIf EndFunctionIf you already have the spell, advance the quest otherwise add the spells. It may still not be the correct thing to do, but it's clearer to see whether or not it is. Edited September 20, 2018 by OldMansBeard Link to comment Share on other sites More sharing options...
Taffer42 Posted September 20, 2018 Author Share Posted September 20, 2018 Thanks for all the help, I've gotten some invaluable advice here! I've tried it out and everything seems to work as intended, althought that UnUpdate function never seems to be called...not sure why. That message box idea helped out with that, and I'm so glad it was so easy to do. I've used similar techniques in debugging in the past, not sure why I didn't think to ask if you could do it here! Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 20, 2018 Share Posted September 20, 2018 It is supposed to be OnUpdate rather than UnUpdate. Link to comment Share on other sites More sharing options...
Recommended Posts