Jump to content

Need help with my Timer script


Radioactivelad

Recommended Posts

So I have an event in which the player sets a timed charge of explosives in order to collapse a cave, depending on their explosives skill the timer gets set to either 30 or 4 seconds.

Now, my script compiles just fine, however, the explosives never go off, so I seem to have a logic loop somewhere. I've made a lot of advancements in my Script-fu but Timers are still a bit arcane to me. Anyone able to explain where I've gone wrong?

The timer section of my script:

 

 

Begin Gamemode

If C4Countdown ==1 && Timer < 30 && CaveCollapsed ==0
showmessage 5ABigClawsCaveC4Success
Set Timer to Timer + GetSecondsPassed

Elseif C4Countdown ==2 && Timer < 4 && CaveCollapsed ==0
Showmessage 5ABigClawsCaveC4Fumble
Set Timer to Timer + GetSecondsPassed

ElseIf C4Countdown ==1 && CaveCollapsed ==0
CollapseEnabler.enable
CollapseEnabler.placeatme C4Explosion
Set CaveCollapsed to 1

ElseIf C4Countdown ==1 && CaveCollapsed ==0
CollapseEnabler.enable
CollapseEnabler.placeatme C4Explosion
Set CaveCollapsed to 1



endif

end

 

Link to comment
Share on other sites

Couple of things. First, make sure this is a quest script, not an object script. GetSecondsPassed doesn't work in an object script, despite compiling (because it doesn't track time, so it always returns 0, so it technically works, but does nothing useful for the script-writer). Sorry, was thinking of non-GameMode blocks.

 

Second, confirm your quest is running.

 

Third, try nesting your conditions instead of using &&.

 

And finally, check on your quest with SQV during debugging to see where the variables aren't doing what they should. This will require the Form ID of your quest and the mod index of your mod.

Edited by EPDGaffney
Link to comment
Share on other sites

Couple of things. First, make sure this is a quest script, not an object script. GetSecondsPassed doesn't work in an object script, despite compiling (because it doesn't track time, so it always returns 0, so it technically works, but does nothing useful for the script-writer).

 

 

I don't believe that's true, as I *do* already have a functioning Timer Object Script that I tried working backwards from to create my Cave Collapse event.

 

 

This is that script if you're curious.

 

SCN 5ASO556APTimerScript

float timer
begin gamemode
if timer < 1250
set timer to timer + GetSecondsPassed
else
set timer to 0
Player.removeitem 5ASO556AP 1 1
Player.additem 5ASO556APREADY 1 1
ShowMessage 5AClaimCheckReady
PlaySound UILevelUp
endif
end

Link to comment
Share on other sites

Actually, that's true. I was thinking of other blocktypes, so sorry for that.

 

The second half of your script seems to be two identical statements.

ElseIf C4Countdown ==1 && CaveCollapsed ==0
CollapseEnabler.enable
CollapseEnabler.placeatme C4Explosion
Set CaveCollapsed to 1
 
ElseIf C4Countdown ==1 && CaveCollapsed ==0
CollapseEnabler.enable
CollapseEnabler.placeatme C4Explosion
Set CaveCollapsed to 1

So, if you were testing with the C4Countdown variable set to 2, that could have been your problem. Best thing to do is check everything with SQV as you test, but unfortunately that doesn't work unless you're using a quest script. You can use SV to check the variables of objects, which is almost equally helpful, but often more annoying to do if you have a lot of things to check. Your other choice is to print things to the console when each change is made in the script, or use MessageEx if you're using NVSE, to put messages in the corner to tell you what's happening as it happens.

 

You may find that nesting these conditions will work better than using && expressions. Have a look here (scroll down or do a find for &&) for more details:

http://wiki.tesnexus.com/index.php/Getting_started_creating_mods_using_GECK#Scripting

 

Another thing you may want to try is separating the explosion placement into another statement that checks only if the enabler has been enabled, because you're enabling it and using it in a script in the same frame. Now, that is actually supposed to work, but still could be the cause of your problem simply because the engine is a bit unpredictable in general. You could add timer checks to your statements at the end, to confirm that it's definitely only trying to do this when it's at the right count.

Link to comment
Share on other sites

Well, talk about a serious "Doh' moment, That condition not being set to 2 was indeed the problem!

 

The thing was, the positive outcome timer was also working incorrectly, but I just managed to fix that by removing a redundant Showmessage result. (Showmessage 5ABigClawsSuccess was used in the Menumode portion of the script.)

Seems strange that would prevent the collapse event but it was what it was.

 

I'll keep your advice about Nesting in mind If I run into anymore problematic scripts, thanks for your help!

Edited by Radioactivelad
Link to comment
Share on other sites

Glad you got it sorted.

 

5ABigClawsCaveC4Success was the name of the message. Not sure if that matters here or not. Was it a message box? I'm a little confused about how this could be a problem as well, unless it was a message box and you had that script running during all menu modes (message boxes are menus).

 

Actually, thinking about it, you probably had another message box with the button that shows that message setting variables, and you had that going in GameMode as well, and I think I can theorise how that went a bit messy.

 

Use GameMode for messages. Or better, use MessageBoxExAlt from JIP LN if you need buttons or a title, and MessageBoxEx if you just want to type a quick message without buttons or a title.

 

Doesn't usually matter, but a quest script still is a bit more efficient for CPU load with a GameMode block if you mind it using custom quest delays and turning it on when it's needed and off when it's not needed (which is easy to do with everything you're doing in this script).

Link to comment
Share on other sites

  • Recently Browsing   0 members

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