Jump to content

Script Not Working


1mike44

Recommended Posts

I have the following script attached to a lever. In my room a have a square of spikes that blockade the player off when raised. In the middle of the spikes is the lever, and it's supposed to make the spikes go up when activated, wait a few seconds then make them go back down. When I hit the switch I get the debugging messages I set up and the lever animations work but the spikes have no animation. One more thing, the spikes are all organized in a FormList, and there are 69 of them in the list.

 

Scriptname SpikeLeverScript extends ObjectReference  

FormList Property Spikes  Auto  

string On = "FullPull"
string Off = "FullPush"
bool Able = true
Int iIndex
ObjectReference Reference


function SetState()
OpenGate()
PlayAnimation(On)
endfunction

Event OnLoad()
 SetState()
endEvent

function OpenGate()
Debug.MessageBox("Opening")
iIndex = -1
Debug.Notification(iIndex)
While(iIndex < 70)
	iIndex = iIndex + 1
	Reference = Spikes.GetAt(iIndex) as ObjectReference
	Reference.PlayAnimation("open")
	Debug.Notification("Hello, world!")
EndWhile
endfunction

function CloseGate()
iIndex = -1
Debug.Notification(iIndex)
While(iIndex < 70)
	iIndex = iIndex + 1
	Reference = Spikes.GetAt(iIndex) as ObjectReference
	Reference.PlayAnimation("close")
	Debug.Notification("Hello, world!")
EndWhile
endfunction

Auto State Inactive

Event OnActivate(ObjectReference akActivateRef)
	GoToState("Active")
	PlayAnimation(Off)
	if(Able == true)
		CloseGate()
		Utility.Wait(15)
		OpenGate()
	endif
	Debug.MessageBox("Resetting")
	Able = false
	Utility.Wait(30)
	Able = true
	PlayAnimation(On)
	Utility.Wait(1)
	GoToState("Inactive")

EndEvent

EndState


State Active
EndState


 

Any idea what is going wrong?

Link to comment
Share on other sites

I didn't test with a formlist, only with a single spike. It should do what you described: When the lever gets pulled, the spikes go up, after a few seconds the spikes lower down and the lever reverts.

 

 

Scriptname SpikeLeverScript extends ObjectReference  

FormList Property Spikes  Auto  

string On = "FullPull"
string Off = "FullPush"
bool Able = true
Int iIndex
ObjectReference Reference


function SetState()
       OpenGate()
       PlayAnimation(On)
endfunction

function OpenGate()
       Debug.MessageBox("Opening")
       iIndex = -1
       Debug.Notification(iIndex)
       While(iIndex < 70)
               iIndex = iIndex + 1
               Reference = Spikes.GetAt(iIndex) as ObjectReference
               Reference.PlayAnimation("open")
               Debug.Notification("Hello, world!")
       EndWhile
endfunction

function CloseGate()
       iIndex = -1
       Debug.Notification(iIndex)
       While(iIndex < 70)
               iIndex = iIndex + 1
               Reference = Spikes.GetAt(iIndex) as ObjectReference
               Reference.PlayAnimation("close")
               Debug.Notification("Hello, world!")
       EndWhile
endfunction

Event OnLoad()
 SetState()
endEvent

Event OnActivate(ObjectReference akActivateRef)               
if (able == true)
	able = false
	PlayAnimation(Off)
	CloseGate()
	Utility.Wait(15)		
	OpenGate()
               PlayAnimation(on)
        able = true
       endif	
EndEvent

Link to comment
Share on other sites

Still not working :(

If this helps, when the game starts I get the message box saying "opening", then a notification saying "-1", and the hello world notification once. When i proceed to the area with the spikes all the spikes are still up. When I pull the lever I get the message box, and the "-1" notification and the "hello world" notification once again. After a while I get the message box again, and both notifications and the lever returns to it's "ON" position. So it seems to me like the error must be somewhere in my while statement for the FormsList, but I cannot figure out what is wrong.

Link to comment
Share on other sites

Try this, don't forget to fill the property.

 

 

Scriptname SpikeLeverScript extends ObjectReference

FormList Property Spikes  Auto  

string On = "FullPull"
string Off = "FullPush"
bool Able = true
Int iIndex
ObjectReference Reference


function SetState()
       OpenGate()
       PlayAnimation(On)
endfunction

function OpenGate()
       Debug.MessageBox("Opening")
       iIndex = Spikes.getsize()
       Debug.Notification(iIndex)
       While(iIndex > 0)
               iIndex -= 1
               Reference = Spikes.GetAt(iIndex) as ObjectReference
               Reference.PlayAnimation("open")
               Debug.Notification("Hello, world!")
       EndWhile
endfunction

function CloseGate()
       iIndex =Spikes.getsize()
       Debug.Notification(iIndex)
       While(iIndex > 0)
               iIndex -= 1
               Reference = Spikes.GetAt(iIndex) as ObjectReference
               Reference.PlayAnimation("close")
               Debug.Notification("Hello, world!")
       EndWhile
endfunction

Event OnLoad()
 SetState()
endEvent

Event OnActivate(ObjectReference akActivateRef)               
       if (able == true)
               able = false
               PlayAnimation(Off)
               CloseGate()
               Utility.Wait(15)                
               OpenGate()
               PlayAnimation(on)
               able = true
       endif   
EndEvent

Link to comment
Share on other sites

Still not working properly, but I think it's an animation thing. When the game starts the poles go partway down then go back up, and the animations wont play again when pull the lever. If I use the sae (Send Animation Event) command in the console i can get individual poles to go down or up.
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...