Script that checks player skill level

Post » Tue Jun 19, 2012 1:51 am

Hi, I'm new here and just started learning to use the CK and scripting. Anyway, I wrote a simple exercise script that checks the player's One Handed skill level at the event OnUpdate() every 5 seconds and then displays a message saying "your skill is level x". It's pretty simple and I'm sure the syntax is correct, the only problem is that I don't know where to put it so that it runs. I put it in the Player Actor but it doesn't do anything there. Any suggestions? Basically I want it to run all the time so that it's always checking and telling me my level (I realize this is not very useful but this is only an exercise for learning purposes).

Thanks in advance.
User avatar
Kieren Thomson
 
Posts: 3454
Joined: Sat Jul 21, 2007 3:28 am

Post » Mon Jun 18, 2012 6:46 pm

Generally, when you want a single instance of a script to run continuously, you'll want to use a quest. In order to make sure your http://www.creationkit.com/OnUpdate event is triggered, make sure you've called http://www.creationkit.com/RegisterForSingleUpdate_-_Form or, as you'll want in this case, http://www.creationkit.com/RegisterForUpdate_-_Form.

P.S. When asking a question about a script you're using, it's always a good idea to post the script as well. Take a look here for more advice - http://www.gamesas.com/topic/1347469-how-to-ask-for-scripting-help/

Cipscis
User avatar
Veronica Martinez
 
Posts: 3498
Joined: Tue Jun 20, 2006 9:43 am

Post » Tue Jun 19, 2012 12:32 am

Ok, I see, thanks for that. I didn't inlcude any code because the problem wasn't with coding, rather with placement (the title is a bit misleading in hindsight). Anyway, that helped thanks.
User avatar
Kahli St Dennis
 
Posts: 3517
Joined: Tue Jun 13, 2006 1:57 am

Post » Mon Jun 18, 2012 6:37 pm

Or something like this:
import gameimport utilitybool NotLooping = truefunction skillLoop()   if NotLooping ; Prevents doing it more than once	  NotLooping = false	  while true		   Debug.Notification("One-Handed Skill: " + Game.GetPlayer().GetAV("OneHanded"))		   Wait(5.0)	 endwhile  endifendfunctionEvent OnUpdate   SkillLoop()EndEvent

Caution: Variables do not propogate between threads...you may need to fiddle with the functions a bit. Making the Boolean Global would probably do it...
User avatar
vanuza
 
Posts: 3522
Joined: Fri Sep 22, 2006 11:14 pm

Post » Tue Jun 19, 2012 6:55 am

Use states to fix your worries about threading:
import Gameimport Utilitybool NotLooping = trueauto State Waiting	Function SkillLoop()		GoToState("Busy")		If (NotLooping) ; Prevents doing it more than once			NotLooping = false			While (true)					Debug.Notification("One-Handed Skill: " + GetPlayer().GetAV("OneHanded"))					Wait(5.0)			EndWhile		EndIf		GoToState("Waiting")	Endfunction	Event OnUpdate()		SkillLoop()	EndEventEndStateState Busy	; Go away, I'm busy!EndState

Cipscis
User avatar
Stephy Beck
 
Posts: 3492
Joined: Mon Apr 16, 2007 12:33 pm

Post » Tue Jun 19, 2012 12:06 am

I guess I should post what I did so others can learn.

I created a quest and added the next script. Once the stage is set, the papyrus fragment will run the "StartChecking()" function so the annoying message starts popping up. I followed the wiki's advice of using RegisterForSingleUpdate() instead of RegisterForUpdate() to prevent it from piling up. This works as I planned.

Scriptname LevelChecker  extends Quest Conditional{Checks level every 5 seconds}Function StartChecking()		   RegisterForSingleUpdate(5)EndFunctionEvent OnUpdate()	Debug.MessageBox("Your One Handed skill level is " + Game.GetPlayer().GetActorValue("onehanded"))	RegisterForSingleUpdate(5)EndEvent
User avatar
Nikki Morse
 
Posts: 3494
Joined: Fri Aug 25, 2006 12:08 pm


Return to V - Skyrim