question about a script

Post » Wed Oct 01, 2014 11:56 am

Hi, so I'm creating this script, and basically, what I want to know is how do I write it so that when I put an 'if' in an OnActivate event, or rather put multiple ifs, and then make something happen, it only happens if ALL of the 'ifs' are true? Because right now, there are eight if statements, and when none of them are true, it comes up with a message box like it's supposed to, but if just one of them is true, it does the thing. But I only want it to do the thing if all eight of them are true :/ Sorry if that was really confusing.. Anyway I'll post the script here so hopefully you can understand what I mean. Thank you :)

Scriptname HeroAmuletActivatorScript extends ObjectReference   Event OnActivate (ObjectReference akActionRef)Actor player = game.getplayer() if (amulet01.IsEnabled())(amulet02.IsEnabled())(amulet03.IsEnabled())(amulet04.IsEnabled())(amulet05.IsEnabled())(amulet06.IsEnabled())(amulet07.IsEnabled())(amulet08.IsEnabled())light1.Enable()light2.Enable()amulet09.Enable(true)sound1.Enable()elseDebug.MessageBox("You have not placed all the amulets in their slots")endifEndEvent ObjectReference Property amulet01  Auto  ObjectReference Property amulet02  AutoObjectReference Property amulet03  AutoObjectReference Property amulet04  AutoObjectReference Property amulet05  AutoObjectReference Property amulet06  AutoObjectReference Property amulet07  AutoObjectReference Property amulet08  AutoObjectReference Property amulet09  AutoObjectReference Property light1  AutoObjectReference Property light2  AutoObjectReference Property sound1  Auto  
User avatar
luke trodden
 
Posts: 3445
Joined: Sun Jun 24, 2007 12:48 am

Post » Wed Oct 01, 2014 12:39 am

Here's what I would do:

Scriptname HeroAmuletActivatorScript extends ObjectReference  ObjectReference[] Property kAmulets AutoObjectReference[] Property kLights AutoObjectReference Property kSound1  Auto  Event OnActivate (ObjectReference akActionRef)	Int i = 0	While(i < (kAmulets.Length - 1)) ;Assumes that the last amulet is the one you want to enable		If(!kAmulets[i].IsEnabled())			Debug.MessageBox("You have not placed all the amulets in their slots") ;You should replace this with a proper message that is displayed using the Show() function.			Return		EndIf		i += 1	EndWhile	i += 1	kAmulets[i].Enable(True)	i = 0	While(i < kLights.Length)		kLights[i].Enable()		i += 1	EndWhile	kSound1.Enable()EndEvent

I think your if-statement is only checking amulet01's state. If you want to have multiple conditions, then you have to use the AND operator, &&:

If((amulet01.IsEnabled()) && (amulet02.IsEnabled()) && (amulet03.IsEnabled()) && (amulet04.IsEnabled()) && (amulet05.IsEnabled()) && (amulet06.IsEnabled()) && (amulet07.IsEnabled()) && (amulet08.IsEnabled()))	;Stuff to execute hereEndIf

Papyrus will stop when it encounters a false condition in this if-statment.

The OR operator, ||, would be used in a similar fashion. However, a similar if-statement with OR operators would cause Papyrus to stop checking the conditions at the first true condition.

EDIT: This might be better:

Spoiler
Scriptname HeroAmuletActivatorScript extends ObjectReference  Message Property kMissingAmulets AutoObjectReference[] Property kRequiredAmulets AutoObjectReference[] Property kRewardAmulets AutoObjectReference[] Property kLights AutoObjectReference[] Property kSounds AutoEvent OnActivate (ObjectReference akActionRef)	Int i = 0	While(i < kRequiredAmulets.Length)		If(!kRequiredAmulets[i].IsEnabled())			kMissingAmulets.Show()			Return		EndIf		i += 1	EndWhile	i = 0	While(i < kRewardAmulets.Length)		kRewardAmulets[i].Enable(True)		i += 1	EndWhile	i = 0	While(i < kLights.Length)		kLights[i].Enable()		i += 1	EndWhile	i = 0	While(i < kSounds.Length)		kSounds[i].Enable()		i += 1	EndWhileEndEvent
User avatar
Teghan Harris
 
Posts: 3370
Joined: Mon Mar 05, 2007 1:31 pm

Post » Wed Oct 01, 2014 8:53 am

Thank you so much MrJack! :) That 3rd one you posted worked :D The first one didn't quite work because the lights and sound got enabled, but not the reward amulet :S Also I tried adding the &&'s into my original script but for some reason that did nothing, it just worked like it did before :/ No idea what the problem is there :S But anyway it works now so yay thank you :) When I publish this update for my mod I will credit you for helping with the script :)

User avatar
Misty lt
 
Posts: 3400
Joined: Mon Dec 25, 2006 10:06 am


Return to V - Skyrim