how do you loop an if statement?

Post » Mon Jun 18, 2012 7:49 am

I'm probably being dumb here, but I've been trying too get an if statement too loop continually when activated by another part of the script. And then be turned off by a different part of the script.

I'm trying too use the if statement too add items too the players inventory, keep track of how many of that item are in the inventory, and "use" the players magicka too add more of that item when the amount drops below a certain value. Right now I can only get it too cycle one time if I place the whole string of commands in the OnEquipped() event. I have tried placing it in an Onupdate() event, but calling regesterforupdate(1) in the onequipped command does nothing...

This is what I have that works right now, even if it only cycles one time. What should I change too make it continually cycle?

Scriptname Summonerbow extends ObjectReferenceAmmo property Summonedarrow AutoEvent OnEquipped(Actor akActor)if (Game.GetPlayer().GetItemCount(Summonedarrow) <= 2)  If (Game.GetPlayer().GetAV("magicka") >= 20)   Game.GetPlayer().AddItem(Summonedarrow, 1, true)   Game.GetPlayer().DamageActorValue("magicka", 20)   Game.GetPlayer().EquipItem(Summonedarrow, false, true)  endifendifendeventEvent OnUnEquipped(Actor akActor)Game.GetPlayer().removeitem(Summonedarrow, 2, true)endevent
User avatar
Dagan Wilkin
 
Posts: 3352
Joined: Fri Apr 27, 2007 4:20 am

Post » Mon Jun 18, 2012 9:12 am

You could nest the If statement within a function, and then call it self on an else?

Function Loop
IF this happens
then do this
Else
run function loop.

end if
User avatar
Susan
 
Posts: 3536
Joined: Sun Jun 25, 2006 2:46 am

Post » Mon Jun 18, 2012 2:44 am

You could use a http://www.creationkit.com/Statement_Reference#While_Statement.
User avatar
Prohibited
 
Posts: 3293
Joined: Tue Jun 12, 2007 6:13 am

Post » Mon Jun 18, 2012 5:27 am

Aah, thanks for the responces. I tried adding a while statement into the OnEquipped event and low and behold, that did the trick. even have a variable too turn it on and off now. thanks for the tips you two.

script now looks like this: and it works.

Scriptname Summonerbow extends ObjectReference Ammo property Summonedarrow AutoEvent OnEquipped(Actor akActor)int arrowtime = 2While arrowtime == 2  Utility.Wait(0.1)  if (Game.GetPlayer().GetItemCount(Summonedarrow) <= 2)   If (Game.GetPlayer().GetAV("magicka") >= 20)    Game.GetPlayer().AddItem(Summonedarrow, 1, true)    Game.GetPlayer().DamageActorValue("magicka", 20)    Game.GetPlayer().EquipItem(Summonedarrow, false, true)   endif  endifendwhileendeventEvent OnUnEquipped(Actor akActor)int arrowtime = 1Game.GetPlayer().removeitem(Summonedarrow, 2, true)endevent

added the wait command too take a bit of the load off papyrus by reducing how often it cycles. does give it a slight hickup with displaying how many arrows are equipped, but I can live with that sinse it doesn't bog down the game any this way.
User avatar
Kate Schofield
 
Posts: 3556
Joined: Mon Sep 18, 2006 11:58 am


Return to V - Skyrim