Is there a more efficient way to do this?

Post » Fri Feb 18, 2011 7:53 pm

I've got a message box that pops up at intervals set by the user (fRTInterval). Is there a more efficient way to do this? Here's what I have, although I haven't play tested, it should work.

If fTotalMinutesPassed > fRTInterval <--------------------------user set, in minutes.  Needed for other actions in the script		If sRealTimeReset == 0			MessageBoxEX "          Current Date and Time          %r          %z, %z %.0f %z:%z %z", svDayoftheWeek, svMonth, fDayoftheMonth, svHumanHours, svHumanMinutes, svAMPM			Set sRealTimeReset to 1			Set fTimer to fTimer + GetSecondsPassed			Set fTimer to fTimer / 60			If fTimer > fRTInterval				Set sRealTimeReset to 0			EndIf		EndIf	EndIf

User avatar
~Sylvia~
 
Posts: 3474
Joined: Thu Dec 28, 2006 5:19 am

Post » Sat Feb 19, 2011 7:31 am

I'm afraid this won't really do what you're after. Once your sRealTimeReset got set to 1 once it won't enter this part of your code anymore unless it is set back to 0. This means after the first run the section which does set it back to 0 isn't processed anymore either.
Once sRealTimeReset is no longer 0 fTimer will not be incremented and never get compared against fRTInterval, even if it would.
You need to do the increment and comparison for reset of the condition before the condition to pop up the messagebox, not inside of it.

What are you intending to achieve with this "Set fTimer to fTimer / 60"? Should it turn seconds in minutes? The first run this might do, fTimer being 0 initially, getting a fraction of seconds added and then divided by 60 makes it a fraction of minutes. This is then compared against the fRTInterval. But next run this fraction of minutes gets another fraction of seconds added and becomes... neither minutes nor seconds anymore. If you treat this then as seconds again for the next division by 60, it will be far smaller than it should be, treating what should be minutes as only seconds now.
If your fRTInterval is in minutes, why not writing the condition like "If fTimer > 60 * fRTInterval"? fTimer could remain a sum of seconds which would properly get incremented each run.

I'd say rewrite this into:
If fTimer > 60 * fRTInterval ; if fRTInterval really is in minutes, this makes it seconds, ready to be compared    Set sRealTimeReset to 0Else    Set fTimer to fTimer + GetSecondsPassedEndIfIf sRealTimeReset == 0    MessageBoxEX "          Current Date and Time          %r          %z, %z %.0f %z:%z %z", svDayoftheWeek, svMonth, fDayoftheMonth, svHumanHours, svHumanMinutes, svAMPM    Set sRealTimeReset to 1    Set fTimer to 0 ; so it starts counting seconds againEndIf

On first run the incrementing and comparison taking place "before" the messagebox pops up doesn't matter here, because sRealTimeReset is 0 and remains 0 until the messagebox pops up, and when this happens fTimer gets reset to 0 anyways to start over at this point.

I hope I got what this script is intended to do right here.
User avatar
~Sylvia~
 
Posts: 3474
Joined: Thu Dec 28, 2006 5:19 am

Post » Fri Feb 18, 2011 9:13 pm

Many thanks, Drake the Dragon. You have become quite the reliable script helper dude.

I still have so much to learn about scripting. In particular I need to learn to review how the engine processes scripts before I commit a script to saving. The engine reads from top to bottom, every frame, except quest scripts, which default to every 5 seconds. But that can be controlled.

Okay, well I just installed 2 OCZ Vertex 3's in a RAID 0 on my machine, so I have to get all my applications and OS up and running the way I want it. So, once I reinstall Oblivion, I'll implement your recommendations and see how it goes.

Thanks again.
User avatar
Darian Ennels
 
Posts: 3406
Joined: Mon Aug 20, 2007 2:00 pm

Post » Sat Feb 19, 2011 6:10 am

Alright. Oblivion is installed, and I'm back to modding. Your script works wonders, Drake the Dragon. Thanks.

I have a question:

What's the best way to track minutes and hours that have passed each game session? I think I have a script that will do it, but it involves resetting short variables and such (I'll post it once I finish and test it). Is there a real simple way to do it that I'm not thinking of? I could always do a separate quest script that only tracks seconds, and call that variable from another script. But even that isn't straightforward...

I thought, initially, that you could just:

Begin...set seconds to seconds + getsecondspassedset minutes to seconds/60...etc...


But now I see that "minutes" will be fractions of a seconds (right?).
User avatar
Avril Churchill
 
Posts: 3455
Joined: Wed Aug 09, 2006 10:00 am

Post » Sat Feb 19, 2011 12:30 am

I could just use seconds for the script and convert to minutes and hours only when I need to, then reset them?
User avatar
Sandeep Khatkar
 
Posts: 3364
Joined: Wed Jul 18, 2007 11:02 am

Post » Sat Feb 19, 2011 4:42 am

I could just use seconds for the script and convert to minutes and hours only when I need to, then reset them?


Yeah, that's what I did. I don't know if it's the best way, but it works.
User avatar
Lucy
 
Posts: 3362
Joined: Sun Sep 10, 2006 4:55 am

Post » Sat Feb 19, 2011 1:35 am

Does "GetSecondsPassed" include time spent in any menu?
User avatar
Austin England
 
Posts: 3528
Joined: Thu Oct 11, 2007 7:16 pm


Return to IV - Oblivion