Gamehour :o

Post » Sat Aug 27, 2011 10:42 pm

Does anyone else have problems with the GameHour command in the script editor?

Simplified example;

If ( GameHour > 17 )
If (GameHour < 8)
*** Move NPC to the pub ****
Endif
Endif

And then I move him back again during normal daytime (shop) hours.

The damn thing seems to work and then crash while resting.

Even if the **move NPC** code is taken out and replaced with "Day Time", "Night Time" messages. It really is winding me up!

Its been a long time since I used this particular command I'm perhaps missing something important and I hope you guys know what it is.

Thanks if anyone knows.
User avatar
Music Show
 
Posts: 3512
Joined: Sun Sep 09, 2007 10:53 am

Post » Sat Aug 27, 2011 9:13 pm

It's a variable, not a command, and my logic processing cupcake has a small problem with your snippet.

Nested 'if' commands require that, in order to reach the next level, the preceding one must be true. It operates as a boolean AND. Thus, your code says:

if ( GameHour < 8 AND GameHour > 17 )


Which obviously fails.

What you want is:

if ( GameHour < 8 )    ; do stuffelseif ( GameHour > 17 )    ; do same stuffendif


Which is the equivalent of a boolean OR.

Edit: Now, the crash I can't explain, without seeing the rest of your code.
User avatar
Chenae Butler
 
Posts: 3485
Joined: Sat Feb 17, 2007 3:54 pm

Post » Sat Aug 27, 2011 3:16 pm

Rofl yup wasn't the best snippet was it :D

I have used elseif by the way but as I said simplified - I forgot for a moment how dumb PC's were and most people would need to see the lot. I think the "do stuff" part will have to be a set variable then after do the real stuff depending on the variables value.

I'm not with my code at the moment but the idea goes like this....

if its before 8 am and after 5 pm then move the NPC somewhere else. i.e. not in their shop because theyre closed!

if its after 8 am but before 5 pm put the bugger back because now hes open for business.

I did remove the "move the NPC" part thinking it was that but it seems as though my code was producing an endless loop (as you state above with the AND function that can never be true)


The following will crash the game when resting;

short stateif ( GameHour < 8 ) 	Set state to 1	    elseif ( GameHour > 17 )     MessageBox "Shop closed" 	Returnendifif ( GameHour >= 8 ) 	Set state to 2	    elseif ( GameHour <= 17 )     MessageBox "Shop Open" 	Returnendif

User avatar
dean Cutler
 
Posts: 3411
Joined: Wed Jul 18, 2007 7:29 am

Post » Sat Aug 27, 2011 6:15 pm

The simplest implementation of that, using times to set other variables as you want, is roughly:

begin "sg_mod1_movenpc"short locationshort stateif ( MenuMode )    returnendifif ( GameHour < 8 )    if ( location != 1 )        Set state To 1    endifelseif ( GameHour > 17 )    if ( location != 1 )        Set state To 1    endifelse    if ( location == 1 )        Set state To 2    endifendifif ( state == 1 )    "npc_id"->PositionCell x, y, z, r, "Cell Name"    Set state To 0elseif ( state == 2 )    "npc_id"->PositionCell x, y, z, r, "Other Cell"endifend


Edit:
Yeah, your code is going to be spamming messages during rest, which is bad. Messages can crash the game anyway. You also don't need to be (and probably shouldn't, though it's not a big deal) returning there. Return resets the script to the start and prevents the remainder from running, it doesn't actually return anything.
User avatar
Ladymorphine
 
Posts: 3441
Joined: Wed Nov 08, 2006 2:22 pm

Post » Sun Aug 28, 2011 2:30 am

Actually the messageboxes are there purely to show it doing something while testing I have no intention of them spamming and slowing the game down.

The return is just a nasty habit I developed many moons ago i.e. pop! push! (old Amiga coder Im afraid)

Funny enough there is a mod that locks/ unlocks doors depending on the time of day and that also crashes my game (I just discovered) - Starting to wonder if its some other mod that is bugging this function although Beth really have some odd requirements for some of their commands.

As for the code I think I will stick to the variable setting type as it makes more sence to me when reading it and also allows me to do other stuff later with this script by changing the vars to global if I need to.

Thanks for the replies mate its been a while since I jumped back into scripting for MW my son used to do it but hes not helping out on this project unfortunately :(
User avatar
Shelby Huffman
 
Posts: 3454
Joined: Wed Aug 08, 2007 11:06 am

Post » Sat Aug 27, 2011 5:39 pm

Maybe the answer is obvious but I cannot figure it out - what determines location variable in this script?
User avatar
Julie Serebrekoff
 
Posts: 3359
Joined: Sun Dec 24, 2006 4:41 am

Post » Sat Aug 27, 2011 2:49 pm

Maybe the answer is obvious but I cannot figure it out - what determines location variable in this script?


Moving the NPC's is the easy part but the confusion sets in with the "when" part :)
User avatar
Lou
 
Posts: 3518
Joined: Wed Aug 23, 2006 6:56 pm

Post » Sat Aug 27, 2011 3:56 pm

Actually the messageboxes are there purely to show it doing something while testing I have no intention of them spamming and slowing the game down.

Spamming them doesn't slow the game down, but if more than 2 or 3 are shown at a time (in a single frame), the game can crash. That interacts badly with various menus, as well.

The return is just a nasty habit I developed many moons ago i.e. pop! push! (old Amiga coder Im afraid)

Morrowind scripts are, for most purposes, parallel and linear. They run from the beginning, test each conditional, and continue until they reach a return or the end of the script. That repeats the next frame. Scripts run one after another, but the order has not been proven to be reliable, so I wouldn't recommend relying on that.

Funny enough there is a mod that locks/ unlocks doors depending on the time of day and that also crashes my game (I just discovered) - Starting to wonder if its some other mod that is bugging this function although Beth really have some odd requirements for some of their commands.

GameHour isn't a function and simply testing the variable is one of the few things not likely to cause a crash. Testing your other mods, though, would be a good idea.

Maybe the answer is obvious but I cannot figure it out - what determines location variable in this script?

Good catch, I actually forgot to set that. It should be handled in the various state blocks near PositionCell.
User avatar
J.P loves
 
Posts: 3487
Joined: Thu Jun 21, 2007 9:03 am


Return to III - Morrowind