zenkci Posted November 8, 2012 Share Posted November 8, 2012 (edited) I am very new to Papyrus, and I am having a problem. I created an activator that runs a script and when the player clicks on the activator it will look for the nearest Actor and set the ownership of a piece of furniture to them so they can use it. The part I am having trouble with is setting the ownership. The furniture object has a name "myFurniture" however if I try to call it within the script I get a compiler error. Since this is an object I created in the render window, it's not defined in the script. Being brand new to this language I don't know how to call or reference an object in the render window. Scriptname TestFindNPC extends ObjectReference Event OnActivate(ObjectReference akActionRef) int c string endLoop string actorID c=0 endLoop=0 while (c < 10) while (endLoop == 0) Actor randomActor = Game.FindRandomActorFromRef(Game.GetPlayer(), 1500.0) if (randomActor != Game.GetPlayer()) endLoop = "1" actorID = randomActor endif endWhile c += 1 endWhile myFurniture.SetActorOwner(actorID) endEvent On an unrelated note, I can't seem to get a nested while statement to work for an 'or' condition. (c>10 || endLoop == 0) (c>10) || (endLoop == 0) ((c>10) || (endLoop == 0)) ((c>10) '||' (endLoop == 0)) Does Papyrus support nested conditions? None of those worked. Am I missing something? Any help on either topic would be appreciated. Edited November 8, 2012 by zenkci Link to comment Share on other sites More sharing options...
Ghaunadaur Posted November 8, 2012 Share Posted November 8, 2012 (edited) Taking a short look, myfurniture needs to be a property that points to the furniture reference you want to set the ownership to. Also, SetActorOwner() needs to be called on an ActorBase. Try this: Scriptname _TestFindNPC extends ObjectReference ObjectReference Property myfurniture auto ActorBase ActorID int c bool endLoop Event OnActivate(ObjectReference akActionRef) c = 0 endLoop = false while (c < 10) while (endLoop == false) Actor randomActor = Game.FindRandomActorFromRef(Game.GetPlayer(), 1500.0) if (randomActor != Game.GetPlayer()) endLoop = true ActorID = randomActor.GetActorBase() endif endWhile c += 1 endWhile myFurniture.SetActorOwner(ActorID) endEvent Edited November 8, 2012 by Ghaunadaur Link to comment Share on other sites More sharing options...
steve40 Posted November 9, 2012 Share Posted November 9, 2012 (edited) Hmm.... a few little problemos: 1) the nested loops' conditions are in the wrong order. If an actor is found in the first iteration (c=0) the first loop will still run 9 more times before finishing. So the first while loop should test "endloop" and the second while loop should test "c < 10", or just AND the two conditions together :)2) what if no actor is found, so ActorID will be null? You'll get an error when you try to setActorOwner on the furniture. Need to check that ActorID is not null, or put it inside the IF statement. Here's one possible way to do it with only one while loop: Scriptname _TestFindNPC extends ObjectReference ObjectReference Property myfurniture auto Event OnActivate(ObjectReference akActionRef) ActorBase ActorID int c = 0 while c < 10 Actor randomActor = Game.FindRandomActorFromRef(Game.GetPlayer(), 1500.0) if randomActor != None && randomActor != Game.GetPlayer() ActorID = randomActor.GetActorBase() myFurniture.SetActorOwner(ActorID) RETURN ; we're done! endif c += 1 endWhile endEvent Note that the RETURN statement will exit completely out of the OnActivate() block, so if you need to add more code after the while loop, the script may need to be slightly different: Scriptname _TestFindNPC extends ObjectReference ObjectReference Property myfurniture auto Event OnActivate(ObjectReference akActionRef) ActorBase ActorID int c = 0 bool endloop = false while c < 10 && !endloop Actor randomActor = Game.FindRandomActorFromRef(Game.GetPlayer(), 1500.0) if randomActor != None && randomActor != Game.GetPlayer() ActorID = randomActor.GetActorBase() endloop = true endif c += 1 endWhile If ActorID != None myFurniture.SetActorOwner(ActorID) EndIf endEvent Edited November 9, 2012 by steve40 Link to comment Share on other sites More sharing options...
steve40 Posted November 10, 2012 Share Posted November 10, 2012 (edited) On an unrelated note, I can't seem to get a nested while statement to work for an 'or' condition. (c>10 || endLoop == 0) You have your logic confused. It should be (c>10 || endLoop == 1) or (c<10 && endLoop == 0) and "endloop" should be a boolean, not a string variable. Edited November 10, 2012 by steve40 Link to comment Share on other sites More sharing options...
Recommended Posts