Rigging an object to explode after X seconds

Post » Sun Jan 30, 2011 3:04 pm

Hey,

I've been at this all day and I've looked through all the timer-related posts and I still can't get this to work.

I'm trying to make it possible for the player to choose an option after activating an object which will make that object explode after several seconds.
I've tried several ways to make it work, here's an example (I've left out all the irrelevant stuff):

SCN BlowUpObjectint iButtonshort GonnaBlowfloat FuseBEGIN onActivate	if GonnaBlow != 1	ShowMessage ObjectMessage	endifENDBEGIN GameMode	set iButton to GetButtonPressed	if iButton == -1		Return	elseif iButton == 2		ShowMessage RunMessage  ;tells the player he's got 5 seconds to run away		set GonnaBlow to 1		set Fuse to 5	endif	if Fuse > 0		set Fuse to (Fuse - GetSecondsPassed)	else		placeatme Explosion	endifEND


And nothing happens. I get the message to run away but I wait and wait and nothing happens. If I place the Fuse timer before the Buttons I can't even activate the object at all. What am I missing here? Isn't the 'if Fuse...' part supposed to run until Fuse is equal to 0?

Any help would be greatly appreciated.
User avatar
Russell Davies
 
Posts: 3429
Joined: Wed Nov 07, 2007 5:01 am

Post » Sun Jan 30, 2011 6:16 pm

Two things -

Explosion is not a valid object name for an explosion. You need to replace that with an actual explosion name.

You are calling the explosion to be spawned every frame that FUSE is zero or less. You need to add something to ensure that only happens once.
User avatar
Karen anwyn Green
 
Posts: 3448
Joined: Thu Jun 15, 2006 4:26 pm

Post » Sun Jan 30, 2011 5:20 am

Two things -

Explosion is not a valid object name for an explosion. You need to replace that with an actual explosion name.

You are calling the explosion to be spawned every frame that FUSE is zero or less. You need to add something to ensure that only happens once.


1. No, I know, I just put 'Explosion' in the example. Everything works fine if I don't have the timer there.

2. Okay, I'll worry about that when I actually get to see the explosion at least once with the timer there :)
User avatar
Jack
 
Posts: 3483
Joined: Sat Oct 20, 2007 8:08 am

Post » Sun Jan 30, 2011 9:00 am

Maybe you should post your real code then. The way you have it setup with the code you posted, 'Explosion' will be spawned immediately upon cell load and every frame there after as FUSE will be equal to zero every frame until the player chooses an option from your message box and that option is #2. Then there would be a 5 second delay before the Explosion starts spawning every frame again. Perhaps your message box options don't match with the script either, maybe post a screenie of that too. I would suspect that the game can't handle spawning the same explosion every frame and is clobbering the script.
User avatar
Nick Tyler
 
Posts: 3437
Joined: Thu Aug 30, 2007 8:57 am

Post » Sun Jan 30, 2011 3:47 am

The "(I've left out all the irrelevant stuff)" is probably why your script is not working.

And some notes:
1. In your GameMode, you should NEVER always intercept the button press like you are doing. You should set a variable when the message is shown, and only check for button press when the variable is set. You then 'unset' the variable when your done intercepting the button press.
2. The second you enter the cell with that script, explosions will start. Since there is nothing to keep you out of the gamemode block of code, and FUSE is set at 0 when the script starts. But since 'explosion' is not valid, the entire script probably did not save and the script is not executing anyway.
User avatar
le GraiN
 
Posts: 3436
Joined: Thu Mar 22, 2007 6:48 pm

Post » Sun Jan 30, 2011 5:51 am

The only thing I really left out is the script for the second button in the menu, but alright, here's my actual code:

SCN KRBioScriptint iButtonBioref	BioLightshort GonnaBlowfloat FuseBEGIN onActivate	if GonnaBlow != 1	ShowMessage KRBioMsg	endifENDBEGIN GameMode	set iButtonBio to GetButtonPressed	if iButtonBio == -1		Return	elseif iButtonBio == 1		ShowMessage KRBioSciMsg		set BioLight to GetLinkedRef		BioLight.Disable	elseif iButtonBio == 2		ShowMessage KRExpMsg		set GonnaBlow to 1		set Fuse to 2	endif	if Fuse > 0		set Fuse to (Fuse - GetSecondsPassed)	else		PlaceAtMe KRBioPodExplosion                    ;a custom explosion I created, it works, I tested it without the timer.	endifEND


And actually, yes, you can have one explosion after the other, I had that when I put the script BEFORE the buttons, just like WillieSea wrote, started right after I entered the cell and wouldn't stop. Not with what I put above, though - no explosion, at any time.

The buttons work perfectly well with the above script. If I put the 'PlaceAtMe' under button #2, the explosion goes off immediately after I press the button (and see the message). No problems there. I just want that to happen 5 seconds after the button is pressed.

It's interesting what you wrote about not intercepting the button presses that way, though. Do you have an example you could post of the method you're talking about?
User avatar
Causon-Chambers
 
Posts: 3503
Joined: Sun Oct 15, 2006 11:47 pm

Post » Sun Jan 30, 2011 6:16 am

Perhaps something like this:
SCN KRBioScriptint iButtonBioref BioLightshort GonnaBlowfloat Fuseshort myStatBEGIN onactivate	if GonnaBlow != 1		ShowMessage KRBioMsg		set myStat to 1	endifENDBEGIN GameMode	if myStat == 1		set iButtonBio to GetButtonPressed		if iButtonBio == -1			Return		elseif iButtonBio == 1			ShowMessage KRBioSciMsg			set BioLight to GetLinkedRef			BioLight.Disable			set myStat to 0		elseif iButtonBio == 2			ShowMessage KRExpMsg			set GonnaBlow to 1			set Fuse to 2			set myStat to 2		endif	endif	if myStat == 2		if Fuse >= 0			set Fuse to Fuse - GetSecondsPassed		else			PlaceAtMe KRBioPodExplosion 1			set myStat to 0	endifEND


Note: You will be placing the explosion at the switch, not sure if thats what you wanted.
Note2: Your placeAtMe has no count, so no exposion will be placed.
User avatar
Ronald
 
Posts: 3319
Joined: Sun Aug 05, 2007 12:16 am

Post » Sun Jan 30, 2011 4:37 am

THANK YOU!

Separating the key presses from the timer with the variable made all the difference, that's what I was missing. Everything works as it should now.

(For some reason the PlaceAtMe works even if I don't have a count there, but I'll keep it there just in case.)

Thanks again.
User avatar
Robyn Howlett
 
Posts: 3332
Joined: Wed Aug 23, 2006 9:01 pm

Post » Sun Jan 30, 2011 8:39 am

Note2: Your placeAtMe has no count, so no exposion will be placed.

PlaceAtMe seems to assume a quantity of 1 when no quantity is specified.. but only in script, just like if (Var) is assumed to be if (Var == 1). Try it from the console and it'll cough up an error message, but in a script it seems to work.
You can see Bethesda use it that way in the DLC02SpiderMine script.
User avatar
ijohnnny
 
Posts: 3412
Joined: Sun Oct 22, 2006 12:15 am

Post » Sun Jan 30, 2011 5:51 pm

Ok, in Oblivion, you must have a count. I assumed that it was the same in Fallout. Its still better coding standards to put the count.
User avatar
Heather Dawson
 
Posts: 3348
Joined: Sun Oct 15, 2006 4:14 pm


Return to Fallout 3