Jump to content

Script for calculating time is buggy


iliary_rus

Recommended Posts

this is a quest script, which refreshes every 5 seconds.

this script makes zzzSleep biger by 1 every hour

 

in my HTC mod

 

 

 

all vars are short

 

; Player's sleep processing while he is sleeping, fast traveling, waiting

 

if (tflag==0)

set lastcheckH to gamehour ; getting last check of time

set lastcheckD to GameDay

set tflag to 1

endif

 

set currentcheckH to gamehour

set currentcheckD to GameDay

 

if ( currentcheckH != lastcheckH) ; time passed

to (zzzZazda + 240*30/timescale)

 

if (currentcheckD == lastcheckD )

set zzzSleep to (zzzSleep + currentcheckH - lastcheckH)

set disptime to (currentcheckH - lastcheckH)

endif

 

if (currentcheckD != lastcheckD )

set zzzSleep to (24 + zzzSleep + currentcheckH - lastcheckH)

set disptime to (24+ currentcheckH - lastcheckH )

endif

 

ShowMessage zzzSleepMESG, disptime

set tflag to 0

endif

 

 

 

sometimes this mod shows uncorrect times.

What is wrong?

Link to comment
Share on other sites

Sorry that I can't answer your question directly, but I would advise you to talk to Smosh here on the forums. I needed a script that changed the time of day instantly once a player activated it & he made it extremely fast & it worked perfect. IMO, he knows what he's doing.

 

-MRG

Link to comment
Share on other sites

Scripting in the CS is somewhat different than several high level languages and have some limitations.

 

This may lead to complications when using comments in the same line of the commands, avoid doing so to be in the sure side. For example, the conditions must appear in the same line of the IF command, but not the statements, so

 

If ; this perform something

conditionA == conditionB

DoSomething

endif

 

is wrong (you have such case in your script)

 

As

 

If (ConditionA == ConditionB) DoSomething Endif

 

is bad too.

 

Just as an advise, try and avoid at maximal the use of many nested ifs, being used to do so may spare you the hell when maintaining bigger scripts. Albeit you may gain some performance this is bad practice considering the limitations of the CS scripting and sometimes, strange behaviors.

 

PS: I'm assuming the lack of the Set command in the

 

if ( currentcheckH != lastcheckH) ; time passed

to (zzzZazda + 240*30/timescale)

 

is copy/paste editing error, since such type of error will not even compile.

 

Edit2: rethink your script asking yourself if you really need so many nested IFs.

Hint: the ElseIf is very useful when emulating the "Case" structure, clean and less prone to mistakes. In the cases where you shall test something inside an IF, maybe you should just test it anyway, outside the nest.

 

Whenever that script above is working, it would fail to assign the different day if the hour is the same.

 

At end. I placed only a few advises because the script posted seems to have copy/paste errors that prevent going deep in the logic itself.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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