Help on a few simple scripts

Post » Sun Nov 18, 2012 1:08 am

Hi,

I started to teach myself scripting tonight, but a few of the scripts I'm trying to write will not compile. I lack the expertise to really figure out why they're not working, so I hope someone here can lend a hand.

What I'm essentially trying to do is kill an NPC well before the player interacts with her and, upon taking an item out of her inventory, she's brought back to life. For reference, the NPC is "darksunilusadead" and the item is "darksunspikes"

I put this script on the NPC:


Scriptname darksunkillilusa extends ObjectReference  Int Property darksunkill  Auto  if (Game.Getdarksunilusadead().GetItemCount(darksunspikes) == 1)   darksunilusadead.killendIf

Errors:


Compiling "darksunkillilusa"...
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\darksunkillilusa.psc(4,1): missing EOF at 'if'
No output generated for darksunkillilusa, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on darksunkillilusa

And this script on the item:

Scriptname darksunilusarevival extends ObjectReference  Int Property NewProperty  Auto  Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)if (newContainer == Game.GetPlayer())				DarksunIlusaDead().resurrectVampireChangeFX.Play(DarksunIlusaDead(), 3.0)endifEndEvent

Errors:


Compiling "darksunilusarevival"...
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\darksunilusarevival.psc(6,16): DarksunIlusaDead is not a function or does not exist
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\darksunilusarevival.psc(6,35): none is not a known user-defined type
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\darksunilusarevival.psc(7,1): variable VampireChangeFX is undefined
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\darksunilusarevival.psc(7,22): DarksunIlusaDead is not a function or does not exist
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\darksunilusarevival.psc(7,17): none is not a known user-defined type
No output generated for darksunilusarevival, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on darksunilusarevival

Thanks for looking!
User avatar
Bad News Rogers
 
Posts: 3356
Joined: Fri Sep 08, 2006 8:37 am

Post » Sat Nov 17, 2012 7:37 pm

Hi,

I started to teach myself scripting tonight, but a few of the scripts I'm trying to write will not compile. I lack the expertise to really figure out why they're not working, so I hope someone here can lend a hand.

What I'm essentially trying to do is kill an NPC well before the player interacts with her and, upon taking an item out of her inventory, she's brought back to life. For reference, the NPC is "darksunilusadead" and the item is "darksunspikes"

Not sure why your first script didn't compile, it compiled fine for me. Here is your second script, rewritten so it will work:
Scriptname darksunilusarevival extends ObjectReference Actor Property DarksunIlusaDead Auto Sound Property VampireChangeFX Auto;Int Property NewProperty  Auto - what's this for?Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer) if (newContainer == Game.GetPlayer())  DarksunIlusaDead.Resurrect()  VampireChangeFX.Play(DarksunIlusaDead) ;What was the 3.0 supposed to do? endifEndEvent

A few pointers:
Notice that I added two new properties - you need to pass in the objects you want to work with, so make sure you actually FILL IN the properties in the CK, otherwise the scripts still won't do anything.

Parenthesis are used for functions, so you had Actor().Resurrect, the property syntax is Actor.Resurrect() - the parens are on the function call. The parens tell the function what parameter values you want to pass, like how you did the Play() function.

Note my comment on the Play() function. If you check the wiki, http://www.creationkit.com/Play_-_Sound only has one parameter value.
User avatar
Joey Avelar
 
Posts: 3370
Joined: Sat Aug 11, 2007 11:11 am

Post » Sat Nov 17, 2012 6:50 pm

That first script still won't compile; I even rewrote it. I tried to set an actor property to DarksunIlusaDead, but apparently I can't do that twice (the other time being the revival script).

The second script compiled just fine - thank you! I haven't scripted since Morrowind, so this property concept is a little alien to me. I appreciate the explanation. Per your comments: the Int property was just an error, I didn't know what I was doing (I left it at default). For the second, I'm trying to play a shader when she resurrects, and the 3.0 should tell the shader to play for 3 seconds. At least, the CK tutorial tells me it will.

Thanks for your help :)
User avatar
Farrah Barry
 
Posts: 3523
Joined: Mon Dec 04, 2006 4:00 pm

Post » Sat Nov 17, 2012 11:42 pm

For the second, I'm trying to play a shader when she resurrects, and the 3.0 should tell the shader to play for 3 seconds. At least, the CK tutorial tells me it will.

Thanks for your help :smile:

Ahh, okay, a Shader. I saw FX and was thinking sound fx, but you probably already figured out that. I hope things make a bit more sense!

Sorry, not sure how that first script supposedly compiled for me, but it's not going to work. I'm trying to understand your logic, but I'm not really sure what your intended goal is. First, I can tell you if you are attaching it to the NPC, the script should extend Actor. Here's an updated version but probably not what you actually need.
Scriptname darksunkillilusa extends ActorObjectReference Property darksunspikes AutoFunction IsDarkSunDead()if !Self.IsDead() && Self.GetItemCount(darksunspikes) == 1)  darksun.Kill()endIfEndFunction

In English, this says: If I'm not dead and I have a darksunspikes, then kill me
I'm really not sure what you intended this function do to, so if this doesn't do what you want, just let me know and I can update it.

Note: I used Self above because it is easier to read, but it isn't required. (I come from a software development background and consider code "readability" much more important than performance for "most" applications, but not all. In this case, I would fully "hope" that Papyrus would compile this the same, but no garauntees on that.)

Function Reference:
http://www.creationkit.com/IsDead_-_Actor

Edit: I don't know what darksunspikes is supposed to refer to, but normally, I would write that condition as:
Self.GetItemCount(darksunspikes) >= 1

That way if there are 2, it will still catch the condition.
User avatar
Chris Guerin
 
Posts: 3395
Joined: Thu May 10, 2007 2:44 pm

Post » Sat Nov 17, 2012 9:07 pm

I want the NPC dead when the player enters the cell, so she can be resurrected when the 'darksunspikes' are removed from her inventory. I've read that the "StartDead" toggle in the CK prevents resurrect from working, so I'm attempting a workaround through script.

I tried your script, but it won't compile. I get this error:

Compiling "darksunkillilusa"...
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\darksunkillilusa.psc(5,58): required (...)+ loop did not match anything at input ')'
No output generated for darksunkillilusa, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on darksunkillilusa

This seems to be the problem line:
if !Self.IsDead() && Self.GetItemCount(darksunspikes) == 1)

darksunspikes refers to a misc item, of which there's only one, so I wrote it == 1 for succinctness (I guess)
User avatar
ijohnnny
 
Posts: 3412
Joined: Sun Oct 22, 2006 12:15 am

Post » Sun Nov 18, 2012 4:03 am

Here's some working script:
Scriptname darksunkillilusa extends ActorMiscObject Property darksunspikes AutoFunction IsDarkSunDead() if !Self.IsDead() && Self.GetItemCount(darksunspikes) == 1  self.Kill() endIfEndFunction

Might even do what you want ;)
User avatar
Alexis Acevedo
 
Posts: 3330
Joined: Sat Oct 27, 2007 8:58 pm

Post » Sun Nov 18, 2012 4:59 am

It compiled! Thank you so much for your help :)
User avatar
Alada Vaginah
 
Posts: 3368
Joined: Sun Jun 25, 2006 8:31 pm

Post » Sat Nov 17, 2012 11:13 pm

Okay, now that I understand the whole picture, here is the updated script with both functions. You'll need to set up a way to call the IsDarkSunDead() function, like through a trigger or something. Note, this is just one script file with two functions.

Scriptname DarkSunScript extends ActorMiscObject Property darksunspikes AutoEffectShader Property VampireChangeFX AutoFunction IsDarkSunDead()If !Self.IsDead() && Self.GetItemCount(darksunspikes) == 1  self.Kill()EndIfEndFunctionEvent OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)If newContainer == Game.GetPlayer() && Self.GetItemCount(darksunspikes) == 0  Self.Resurrect()  VampireChangeFX.Play(self, 3.0)EndIfEndEvent

Edit:
I changed the code to use the shader as you wanted. So make sure you set the shader property correctly in the CK.
User avatar
Kieren Thomson
 
Posts: 3454
Joined: Sat Jul 21, 2007 3:28 am

Post » Sun Nov 18, 2012 12:59 am

You can omit most instances of 'Self'...
self.Kill()
...as functions can be called implicitly.
Kill()
'Self', really, is only needed if passing the calling object as an argument.
VampireChangeFX.Play(self, 3.0)
User avatar
Ross Thomas
 
Posts: 3371
Joined: Sat Jul 21, 2007 12:06 am

Post » Sat Nov 17, 2012 9:30 pm

You can omit most instances of 'Self'...
self.Kill()
...as functions can be called implicitly.
Kill()
'Self', really, is only needed if passing the calling object as an argument.
VampireChangeFX.Play(self, 3.0)

Note: I used Self above because it is easier to read, but it isn't required. (I come from a software development background and consider code "readability" much more important than performance for "most" applications, but not all. In this case, I would fully "hope" that Papyrus would compile this the same, but no garauntees on that.)

Edit: I stated the above in my first reply to him.... but as he is learning Papyrus, it's more intuitive to see the "self" to read how the function is working.

JustinOther, I seem to remember you doing some performance anolysis before? Was there any difference in the time? I would seriously hope the Papyrus compiler optimizes the code, but it's so slow, I'm not sure how good it is.
User avatar
Sweet Blighty
 
Posts: 3423
Joined: Wed Jun 21, 2006 6:39 am

Post » Sat Nov 17, 2012 7:51 pm

Ah. I'd only read the code so I guess I'm preaching to the choir :P Strange, to me at least, that one would find code easier to read with anything extraneous. :shrug:
User avatar
Justin Hankins
 
Posts: 3348
Joined: Fri Oct 26, 2007 12:36 pm

Post » Sat Nov 17, 2012 4:23 pm

Strange, to me at least, that one would find code easier to read with anything extraneous. :shrug:

It's not extraneous though, it's implicit, as you stated the first time. Since it's implicit, someone new who doesn't know it's automatically happening behind the scenes may be lost as to what the heck is really going on.
User avatar
kasia
 
Posts: 3427
Joined: Sun Jun 18, 2006 10:46 pm

Post » Sat Nov 17, 2012 10:44 pm

If someone new sees functions called implicitly in examples, they're more likely to put it together sooner that they needn't proliferate unnecessary/extraneous code, I'd argue. I know I wish I'd figured it out earlier. Many of my earlier Oblivion/Fallout scripts would have been simpler/easier on the eyes had I not adopted the unfortunate habit of unnecessarily using 'GetSelf'/'This'. Papyrus' 'Self', used in an ObjectReference or Actor script, is anologous.
User avatar
Spencey!
 
Posts: 3221
Joined: Thu Aug 17, 2006 12:18 am

Post » Sat Nov 17, 2012 4:27 pm

If someone new sees functions called implicitly in examples, they're more likely to put it together sooner that they needn't proliferate unnecessary/extraneous code, I'd argue. I know I wish I'd figured it out earlier. Many of my earlier Oblivion/Fallout scripts would have been simpler/easier on the eyes had I not adopted the unfortunate habit of unnecessarily using 'GetSelf'/'This'. Papyrus' 'Self', used in an ObjectReference or Actor script, is anologous.

I see your point.

The same argument can be made that comments are extraneous, and I consider the "Self" to be self commenting code.

I'd only be concerned though if the compiler does not optimize the code. The same argument could be made for a condition check like > -1 versus >= 0, as the first is a single a single instruction, the latter is two instructions, but again, most compilers will optimize it. The second example is generally easier to read, and therefor, easier to maintain. (Realize, code maintenance can easily be more expensive than code development.)

I'll have to run some speed tests tomorrow to see how well the compiler is optimizing. As slow as Papyrus is anyway, I would be most concerned with effeciency in the compiled code and less with the source code.
User avatar
Nathan Risch
 
Posts: 3313
Joined: Sun Aug 05, 2007 10:15 pm

Post » Sat Nov 17, 2012 9:35 pm

Okay, now that I understand the whole picture, here is the updated script with both functions. You'll need to set up a way to call the IsDarkSunDead() function, like through a trigger or something. Note, this is just one script file with two functions. Edit: I changed the code to use the shader as you wanted. So make sure you set the shader property correctly in the CK.

Thanks! So... what would a trigger look like? Like a global script that checks whether the player is in the same cell as this NPC?

And thank you both, for showing me all the code and explaining the implied aspects for the scripts. It does help a lot.
User avatar
Lou
 
Posts: 3518
Joined: Wed Aug 23, 2006 6:56 pm

Post » Sat Nov 17, 2012 7:44 pm

Thanks! So... what would a trigger look like? Like a global script that checks whether the player is in the same cell as this NPC?

No, fortunately you don't have to do that, as it would be very ineffecient. Just put a marker where you want the event to occur, depending on your setup. Here's a video that should get you started: http://www.youtube.com/watch?v=4EtFXkvcgIA
User avatar
Katie Louise Ingram
 
Posts: 3437
Joined: Sat Nov 18, 2006 2:10 am


Return to V - Skyrim