A simple script

Post » Thu Jul 02, 2015 3:23 pm

My typical poor skill with scripting has reared its ugly head again. All I want to do is make it so that when you activate an unlit brazier two grates move apart from each other, creating an opening and the unlit brazier is replaced by a lit one. It cannot move back, this is one time. Sounds simple, but all I get is the brazier replaced and a sound played!

Begin az_scr_ashogala_brazierShort StateFloat Timer if ( MenuMode == 1 )	Returnendifif ( OnActivate == 1 )	if ( az_ashogala_grate_state > 0 )		Return	elseif ( az_ashogala_grate_state == 0 )		Set az_ashogala_grate_state to 1		Set State to 1		PlaceAtMe "md_light_az_ruin_brazier_512" 1 0 0		"md_act_grate_Ashogala_01"->Playsound3DVP "Stone Door Open 1" 1.0 1.0		Set Timer to Timer + GetSecondsPassed		If ( Timer <= 15 )			"md_act_grate_Ashogala_01"->MoveWorld X 10			"md_act_grate_Ashogala_02"->MoveWorld X -10		Else			Set az_ashogala_grate_state to 2			Set State to 2			Set Timer to 0			Disable		Endif	EndifEndifend az_scr_ashogala_brazier

After looking at the Ghostgate script, I tried adding a global, but that did not work...

Thanks for any help. :)

User avatar
Emzy Baby!
 
Posts: 3416
Joined: Wed Oct 18, 2006 5:02 pm

Post » Thu Jul 02, 2015 9:56 am

Oh, forgot to mention that I put the LocalState script on the grates but that didn't make them move either...

User avatar
Lily
 
Posts: 3357
Joined: Mon Aug 28, 2006 10:32 am

Post » Thu Jul 02, 2015 1:02 pm

onactivate is only for one frame i believe. you you'll need to divorce the timer functions from that if block.

User avatar
Anthony Diaz
 
Posts: 3474
Joined: Thu Aug 09, 2007 11:24 pm

Post » Thu Jul 02, 2015 1:57 am

like gjerkson mentioned, onactivate is only set for one frame when the player clicks it. It's 0 again the next frame. This run-every-frame thing is why you see a lot of 'state' constructs in morrowind scripts. Try something like this:

Begin az_scr_ashogala_brazier	Short State	Float Timer		if ( getdisabled == 1 )		set delete to 1	endif	if ( MenuMode == 1 )		Return	endif	if ( State == 0 )		if ( OnActivate == 1 )			PlaceAtMe "md_light_az_ruin_brazier_512" 1 0 0			"md_act_grate_Ashogala_01"->Playsound3DVP "Stone Door Open 1" 1.0 1.0			set State to 1		endif	endif	if ( State == 1 )		Set Timer to Timer + GetSecondsPassed		If ( Timer <= 15 )			"md_act_grate_Ashogala_01"->MoveWorld X 10			"md_act_grate_Ashogala_02"->MoveWorld X -10			return		endif		set State to 2		Disable	endifend az_scr_ashogala_brazier

I haven't tested this but I hope you get the gist of it. Like you mentioned, this script is a one time thing. It doesn't provide functionality for closing.

As you can see, it only responds to onactivate when State is 0 (which is the default value of short vars), which is only once because it's set to 1 when activated. Now State is 1, it will repeatedly execute the moveworld functions each frame for 15 seconds. After that, state is set to 2 and it will be impossible to interact with the object again. It also gets disabled, and on the next run (frame) deleted.

Hope this helps!

User avatar
Sammie LM
 
Posts: 3424
Joined: Thu Nov 30, 2006 1:59 pm

Post » Thu Jul 02, 2015 9:55 am

They're moving! So many of my scripts use OnActivate, that I wasn't even really thinking of its limitations.

Thanks both of you!

User avatar
Lauren Denman
 
Posts: 3382
Joined: Fri Jun 16, 2006 10:29 am


Return to III - Morrowind