Jump to content

Script not operating as expected


Chrophiss

Recommended Posts

Hello, i have made a script mostly by myself as i am trying to learn how to script for myself.

But now i have run into a problem i can't seem to fix. I tried pretty much everything i could think of.

 

I am trying to do the following:

Player opens a door, player controls disabled, deathclaw on other side turns around to face the player, door automatically closes, controls restored. (note, i wish to add more parts such as disabling of the deathclaw and locking the door later. After i get this part to work.)

 

This is what i have:

scn NWSDeathclawstartScript

int DoOnce
float timer

Begin onactivate Player

    if DoOnce == 0
        Set Timer to 5
 
       activate
        DeathclawdoorREF.activate

        DisablePlayerControls 1 1 1 1 1 1 1
        Claw1REF.Playgroup TurnRight 1
        Set DoOnce to 1
    endif

     if ( timer > 0 )                                                
         set timer to timer - getSecondsPassed
     else
          activate
          DeathclawdoorREF.activate

          EnablePlayerControls 1 1 1 1 1 1 1
    endif

End

Now it all seems to work up until the first endif. Everything i want done after will not kick in. Player controls are not restored and door will not close. Any suggestions or tips for how to deal with it? Thanks!.

Link to comment
Share on other sites

Try

 

scn NWSDeathclawstartScript

int DoOnce
float timer

Begin onactivate Player

    if DoOnce == 0
        Set Timer to 5
 
       activate
        DeathclawdoorREF.activate

        DisablePlayerControls 1 1 1 1 1 1 1
        Claw1REF.Playgroup TurnRight 1
        Set DoOnce to 1
    endif

     if ( timer > 0 )                                                
         set timer to getSecondsPassed
     else
          activate
          DeathclawdoorREF.SetOpenState 3

          EnablePlayerControls 1 1 1 1 1 1 1
    endif

End
Link to comment
Share on other sites

Neither of those will work, the onActivate block only runs once. You need to shift the timer code into a gameMode block; something like this:
scn NWSDeathclawstartScript

int DoOnce
float timer
short bTimerTrigger ;boolean value to decide if the timer code needs to run.
short sFrameSkip ;skip a frame to avoid both blocks trying to execute simultaneously

Begin onactivate Player

if DoOnce == 0

Set Timer to 5
set bTimerTrigger to 1 ;enables timer code
set sFrameSkip to 0 ;initialize frameskip
activate

DeathclawdoorREF.activate

DisablePlayerControls 1 1 1 1 1 1 1
Claw1REF.Playgroup TurnRight 1

Set DoOnce to 1

endif

End

begin gameMode

if (bTimerTrigger)
if (sFrameSkip < 1)
set sFrameSkip to sFrameSkip + 1
else
if ( timer > 0 )
set timer to getSecondsPassed
else
activate
DeathclawdoorREF.SetOpenState 3
EnablePlayerControls 1 1 1 1 1 1 1
set bTimerTrigger to 0 ;disables timer code
endif
endIf
endIf

end
Edit: FOR GREAT JUSTICE and formatting bollixing up across pastes. Edited by Xaranth
Link to comment
Share on other sites

Hi, thank you both for posting! I tried both your scripts just in case, yet both get the same result as my original. The door does not close nor are player controls restored.

 

Note: This is the first time i'm getting confronted with btimertrigger and sframeskip so i am not sure of what exactly they do. Also, Xaranth i do not know what you meant by that final edit sentence. Quite confused. Thanks!

Link to comment
Share on other sites

Oh, when I pasted in that code the formatting got all messed up, so I had to edit the post. Also, if I'd taken a half-second to read the code rather than just c/ping it... Anyway, try this one:

scn NWSDeathclawstartScript

int DoOnce
float timer
short bTimerTrigger ;boolean value to decide if the timer code needs to run.
short sFrameSkip ;skip a frame to avoid both blocks trying to execute simultaneously

Begin onactivate Player

    if DoOnce == 0

	Set Timer to 5
	set bTimerTrigger to 1 ;enables timer code
	set sFrameSkip to 0 ;initialize frameskip
	activate

        DeathclawdoorREF.activate

        DisablePlayerControls 1 1 1 1 1 1 1
        Claw1REF.Playgroup TurnRight 1

        Set DoOnce to 1
		
    endif

End

begin gameMode

	if (bTimerTrigger)
		if (sFrameSkip < 1)
			set sFrameSkip to sFrameSkip + 1
		else
			if ( timer > 0 )                                                
				set timer to (timer - getSecondsPassed) ; *** THIS IS THE CHANGED LINE *** I missed that Timer wasn't updated properly.
			else
				activate
				DeathclawdoorREF.SetOpenState 3
				EnablePlayerControls 1 1 1 1 1 1 1
				set bTimerTrigger to 0 ;disables timer code
			endif
		endIf
	endIf

end
Regarding bTimerTrigger and sFrameSkip:

 

they're simply control variables. Theoretically, sFrameSkip is unneccessary, but... I'm paranoid when it comes to this engine.

 

Anyway. A gameMode block runs every frame. We use bTimerTrigger as a control variable to decide when the timer code will run. sFrameSkip is there to make the gameMode block 'skip' a frame, just in case the activate block and the timer block try to execute simultaneously. It's basically a one-frame delay just to ensure that the Activate code has completely parsed before we try to start parsing the gameMode code.

Link to comment
Share on other sites

Thank you for the clarification.

I tested the script now and it seems to function properly now!

Thank you very much. I had been getting headaches over this.

 

I will continue work on this on a later time but if i have any more questions concerning this script/topic i'll be sure to post back here!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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