Seven League Boots (script not compiling)

Post » Tue Jun 19, 2012 6:37 am

So, I am a complete newbie to the creation kit, having never used the earlier construction kits, and am having some trouble with scripting. My first script was an attempt to create a spell which would teleport the caster to the projectile's impact location, and that didn't work so well (I may end up revisiting that later, once I know how this stuff works). My latest endeavor has been to create a pair of seven-league-boots using a script, rather than an enchantment, just as an experiment. After some time, I ended up with this script:

Spoiler
Scriptname SevenLeagueBootsSCR extends ObjectReference  Event OnEquipped(Actor akActor)   Function akActor.SetActorValue("SpeedMult", 5)   EndFunctionEndEventEvent OnUnequipped(Actor akActor)   Function akActor.SetActorValue("SpeedMult", 1)   EndFunctionEndEvent

Much to my dismay, it did not even compile. This was after several hours of research into papyrus, so I was a little disappointed. If someone could point out what I did wrong, or, even better, explain it, that would be much appreciated.
User avatar
Princess Johnson
 
Posts: 3435
Joined: Wed Feb 07, 2007 5:44 pm

Post » Tue Jun 19, 2012 2:43 pm

When you use the keyword Function, it signals the start of a function definition. To call a function, you want to use syntax like this:
akActor.SetActorValue("SpeedMult", 5)

Cipscis
User avatar
mike
 
Posts: 3432
Joined: Fri Jul 27, 2007 6:51 pm

Post » Tue Jun 19, 2012 11:08 am

Oh.
So, something like

Spoiler
Scriptname SevenLeagueBootsSCR extends ObjectReferenceEvent OnEquipped(Actor akActor)   akActor.SetActorValue("SpeedMult", 5)EndEventEvent OnUnequipped(Actor akActor)   akActor.SetActorValue("SpeedMult", 1)EndEvent

This?
User avatar
Miss K
 
Posts: 3458
Joined: Sat Jan 20, 2007 2:33 pm

Post » Tue Jun 19, 2012 6:10 am

That looks like it would compile to me and do what you expect, yes. I know there are some caveats to manipulating actor values via script, but I'm not very familiar with them. What you're using here will probably be fine, although it might pay to keep in mind another script might modify the player's "SpeedMult" actor value while the boots are equipped.

I also thing (again, actor values aren't something I work with often, so this isn't based on my own experience) that extra steps need to be taken before changes to the "SpeedMult" actor value will be reflected in-game. Hopefully someone else will be able to answer these questions.

Cipscis
User avatar
A Lo RIkIton'ton
 
Posts: 3404
Joined: Tue Aug 21, 2007 7:22 pm

Post » Tue Jun 19, 2012 5:42 am

Thank you very much for your help. I guess I'd just assumed that the syntax for functions was the same as events, and evidently I was wrong.
User avatar
Schel[Anne]FTL
 
Posts: 3384
Joined: Thu Nov 16, 2006 6:53 pm

Post » Tue Jun 19, 2012 7:29 am

Actually no, you were right. The problem is that you were confusing the syntax required for defining a function or event with the syntax for calling a function or event. If I want to trigger an event manually, I'd use the same syntax as I'd use for calling a function. If I want to define a function, I'd use very similar syntax to defining an event (like you tried to use at first).

Cipscis
User avatar
Rachael Williams
 
Posts: 3373
Joined: Tue Aug 01, 2006 6:43 pm

Post » Tue Jun 19, 2012 9:39 am

Oh, that makes a lot more sense. Thanks for clarifying.
User avatar
Prisca Lacour
 
Posts: 3375
Joined: Thu Mar 15, 2007 9:25 am

Post » Tue Jun 19, 2012 7:03 am

Okay, I tested the boots, and they worked. In an attempt to up the ante a bit I decided to make the player gradually accelerate when they begin sprinting. I eventually ended up with the following code.

Spoiler

Scriptname SevenLeagueBootsSCR extends ObjectReferenceint equip = 0int spd = 100registerForUpdate(1)Event OnEquipped(Actor akActor)   equip = 1EndEventif equip == 1   if akActor.IsSprinting() == 1	  Event OnUpdate()		 spd = (spd+10)		 akActor.SetActorValue("SpeedMult", spd)	  EndEvent   endif   if akActor.IsSprinting() == 0	  spd = 100	  akActor.SetActorValue("SpeedMult", spd)   endifendifEvent OnUnequipped(Actor akActor)   equip = 0   akActor.SetActorValue("SpeedMult", 100)EndEvent
Unfortunately, this did not compile, and once again, I am at a loss for debugging.

(edit)
Actually, they work even though the script does not compile. Odd.
User avatar
matt oneil
 
Posts: 3383
Joined: Tue Oct 09, 2007 12:54 am

Post » Tue Jun 19, 2012 4:56 am

All your code except for variable/property declarations needs to be inside the events or inside defined functions

You probably want it like this
Scriptname SevenLeagueBootsSCR extends ObjectReferenceint equip = 0int spd = 100Event OnEquipped(Actor akActor)   equip = 1   registerForUpdate(1)EndEventEvent OnUpdate()   if equip == 1	  if akActor.IsSprinting() == 1		 spd = spd + 10		 akActor.SetActorValue("SpeedMult", spd)	  endif	  if akActor.IsSprinting() == 0		 spd = 100		 akActor.SetActorValue("SpeedMult", spd)	  endif   endifEndEventEvent OnUnequipped(Actor akActor)   equip = 0   akActor.SetActorValue("SpeedMult", 100)EndEvent
User avatar
Daddy Cool!
 
Posts: 3381
Joined: Tue Aug 21, 2007 5:34 pm

Post » Tue Jun 19, 2012 9:05 am

Oh okay. That makes sense. Thanks! Also, should I have it unregister for updates when they are unequipped, or does it not matter?

-edit-
Oh wait, nevermind. That didn't compile either.

Also, does the actor definition 'akActor' persist outside of the OnEquipped event?
User avatar
Angelina Mayo
 
Posts: 3427
Joined: Wed Jan 24, 2007 4:58 am

Post » Tue Jun 19, 2012 7:13 am

Oh, should have seen that, no it does not, you would need to add a variable at the top of type Actor

Scriptname SevenLeagueBootsSCR extends ObjectReferenceint equip = 0int spd = 100actor equippedActorEvent OnEquipped(Actor akActor)   equippedActor = akActor   equip = 1   registerForUpdate(1)EndEventEvent OnUpdate()   if equip == 1	  if equippedActor.IsSprinting() == 1		 spd = spd + 10		 equippedActor.SetActorValue("SpeedMult", spd)	  endif	  if equippedActor.IsSprinting() == 0		 spd = 100		 equippedActor.SetActorValue("SpeedMult", spd)	  endif   endifEndEventEvent OnUnequipped(Actor akActor)   equip = 0   equippedActor.SetActorValue("SpeedMult", 100)EndEvent

Also I don't think you need to unregister for the updates, I read the creationkit wiki entry on this and I believe that it will automatically unregister when the boots get unequipped (although it doesn't specifically say it will for equipped items I still think it will)
User avatar
Alyna
 
Posts: 3412
Joined: Wed Aug 30, 2006 4:54 am

Post » Tue Jun 19, 2012 2:45 pm

I thought so. I actually tried to do this earlier, but I mistakenly defined the actor as a variable. Not sure why I did that. Thanks.

and...

Yes, it compiled! Whoo!

Thanks!

Hmm. they still don't work. I'm going to try triggering 'IsSprinting' every update to refresh the speedmult.
User avatar
City Swagga
 
Posts: 3498
Joined: Sat May 12, 2007 1:04 am

Post » Tue Jun 19, 2012 6:28 am

Np :] and the actor variable is actually a variable of type actor, and i just noticed i missed a p in the initial declaration of equippedActor
User avatar
Natalie J Webster
 
Posts: 3488
Joined: Tue Jul 25, 2006 1:35 pm

Post » Tue Jun 19, 2012 10:10 am

I noticed that too and fixed it. Now I just need to figure out how to refresh the SpeedMult.

Any ideas, anyone?
User avatar
Stephanie Valentine
 
Posts: 3281
Joined: Wed Jun 28, 2006 2:09 pm

Post » Tue Jun 19, 2012 1:53 pm

Okay, figured it out. Apparently, you can refresh the speedmult data by oscillating the player's carry weight. I ended up doing so with the following code:

Spoiler
Scriptname SevenLeagueBootsSCR extends ObjectReferenceint equip = 0int spd = 100actor equippedActorint osc = 0Event OnEquipped(Actor akActor)   equippedActor = akActor   equip = 1   registerForUpdate(1)EndEventEvent OnUpdate()   if osc == 0	  equippedActor.ModAV("CarryWeight", 0.01)   endif   if osc == 1	  equippedActor.ModAV("CarryWeight", -0.01)   endif   if equip == 1	  if equippedActor.IsSprinting() == 1		 spd = spd + 10		 equippedActor.SetActorValue("SpeedMult", spd)	  endif	  if equippedActor.IsSprinting() == 0		 spd = 100		 equippedActor.SetActorValue("SpeedMult", spd)	  endif   endifEndEventEvent OnUnequipped(Actor akActor)   equip = 0   equippedActor.SetActorValue("SpeedMult", 100)EndEvent

You can see that I have a variable called 'osc' which just toggles between 0 and 1, thereby activating if statements which increase or decrease carryweight by 0.01 respectively.

-edit-
Whoops, that doesn't work, forgot to have osc actually change.
User avatar
Joey Bel
 
Posts: 3487
Joined: Sun Jan 07, 2007 9:44 am

Post » Tue Jun 19, 2012 4:33 pm

Sorry 'bout that. Fixed the code, but regrettably, it didn't actually work.
User avatar
Andrew Perry
 
Posts: 3505
Joined: Sat Jul 07, 2007 5:40 am

Post » Tue Jun 19, 2012 8:53 am

I figured out why it doesn't work. I stuck a debug.trace into the onupdate event, and it never appeared (it should have, every second). Why isn't the update happening?
User avatar
Robert Bindley
 
Posts: 3474
Joined: Fri Aug 03, 2007 5:31 pm

Post » Tue Jun 19, 2012 6:38 am

Debug.trace doesnt output to the game, it puts the message in some log file, I'm not sure if you know this or not, debug.notification or debug.messagebox puts the message on screen. There also may be settings you need for debug.trace, I'm not sure.
User avatar
Robert Devlin
 
Posts: 3521
Joined: Mon Jul 23, 2007 2:19 pm

Post » Tue Jun 19, 2012 3:26 am

Yeah, it still doesn't work.

I'm going to try this:
Function SomeFunction()                   registerForUpdate(1)EndFunction

That didn't work either.
User avatar
ashleigh bryden
 
Posts: 3446
Joined: Thu Jun 29, 2006 5:43 am

Post » Tue Jun 19, 2012 11:06 am

Hm, off the creationkit wiki
Registers this active magic effect/alias/form for periodic update events.
...
Only the specific form, alias, or magic effect that registered will get the event - it will not be relayed to attached aliases or magic effects.

I guess you can't put it on the item and use OnUpdate, you can however make a magic effect and enchant and add it to the boots as an enchantment. I just tested this and the OnUpdate event is working.
User avatar
Solène We
 
Posts: 3470
Joined: Tue Mar 27, 2007 7:04 am

Post » Tue Jun 19, 2012 2:51 pm

I'll have to try that. If what you said is true, it should work. I'm not sure if I could use onequipped with a magic effect, though.
User avatar
Angela
 
Posts: 3492
Joined: Mon Mar 05, 2007 8:33 am

Post » Tue Jun 19, 2012 8:37 am

Use OnEffectStart and OnEffectFinish instead
User avatar
:)Colleenn
 
Posts: 3461
Joined: Thu Aug 31, 2006 9:03 am

Post » Tue Jun 19, 2012 11:02 am

Oh, I hadn't thought if that! You're right, that would probably function the same (eg the effect starts when they are equipped and ends when unequipped).
User avatar
Bones47
 
Posts: 3399
Joined: Fri Nov 09, 2007 11:15 pm

Post » Tue Jun 19, 2012 12:24 pm

I now have the script, in a magic effect, in an enchantment, on the boots.

The script is now as follows:

Spoiler
Scriptname SevenLeagueBootsSCR extends ObjectReferenceint spd = 100   actor equippedActorint osc = 0Event OnEffectStart(Actor akTarget)   Debug.MessageBox("The effect has started" )   equippedActor = akTarget   registerForUpdate(1)EndEventEvent OnUpdate()   Debug.MessageBox("it works" )   if osc == 0      equippedActor.ModAV("CarryWeight", 1)      osc = 1   elseif osc == 1      equippedActor.ModAV("CarryWeight", -1)      osc = 0   endif   if equippedActor.IsSprinting() == 1      spd = spd + 10      equippedActor.SetActorValue("SpeedMult", spd)   endif   if equippedActor.IsSprinting() == 0      spd = 100      equippedActor.SetActorValue("SpeedMult", spd)   endifEndEventEvent OnEffectFinish(Actor akTarget)   equippedActor.SetActorValue("SpeedMult", 100)EndEvent

And it still doesn't work!

None of the messageboxes are even appearing, meaning that the effect is never even starting!
User avatar
Jenna Fields
 
Posts: 3396
Joined: Mon Dec 11, 2006 11:36 am

Post » Tue Jun 19, 2012 2:56 am

'extends ObjectReference' needs to be changed to 'extends ActiveMagicEffect'
'OnEffectStart(Actor akTarget)' should be 'OnEffectStart(Actor akTarget, Actor akCaster)' same thing with OnEffectFinish
User avatar
rolanda h
 
Posts: 3314
Joined: Tue Mar 27, 2007 9:09 pm

Next

Return to V - Skyrim