Script timing problem

Post » Sun May 01, 2011 4:55 pm

I'm trying to write a script that removes a spell effect after an hour. There seems to be a problem with my timing though, as the spell effect is not being removed in-game, ever. I don't want to use GetSecondsPassed because I want the effects to wear off if the player rests as well, so I'm trying to use a GameHour check. BB_Grimoire_Timer is a global float variable, not a local.


Begin BB_Grimoire_GlobalIf ( BB_Grimoire_Timer == 0 )	Set BB_Grimoire_Timer to GameHourEndifIf ( GameHour < ( BB_Grimoire_Timer + 1.0 ) ) ;something is wrong with my scripting in this block	If ( GameHour > ( BB_Grimoire_Timer - 23.0 ) ) ;checks if the hour changes from midnight to 1 am?		Return	EndifEndif;this part below is not executing, so the script must be returning no matter what time it isIf ( Player->GetSpell "grim_alteration" == 1 )	Player->RemoveSpell "grim_alteration"Elseif ( Player->GetSpell "grim_conjuration" == 1 )	Player->RemoveSpell "grim_conjuration"Elseif ( Player->GetSpell "grim_destruction" == 1 )	Player->RemoveSpell "grim_destruction"Elseif ( Player->GetSpell "grim_enchant" == 1 )	Player->RemoveSpell "grim_enchant"Elseif ( Player->GetSpell "grim_illusion" == 1 )	Player->RemoveSpell "grim_illusion"Elseif ( Player->GetSpell "grim_mysticism" == 1 )	Player->RemoveSpell "grim_mysticism"Elseif ( Player->GetSpell "grim_restoration" == 1 )	Player->RemoveSpell "grim_restoration"EndifMessageBox "You feel the effects of the grimoire wash away."Set BB_Grimoire_Timer to 0StopScript BB_Grimoire_GlobalEnd


Does anyone know what I did wrong with my timings here?
User avatar
helliehexx
 
Posts: 3477
Joined: Fri Jun 30, 2006 7:45 pm

Post » Sun May 01, 2011 8:14 pm

.
User avatar
Jonathan Egan
 
Posts: 3432
Joined: Fri Jun 22, 2007 3:27 pm

Post » Mon May 02, 2011 3:10 am

Maybe I'm not following this correctly, but... if BB_Grimoire_Timer is set at... oh, say 6am.

Gamehour gets to be 7.01, and that is greater than 6 and satisfies your first if condition to move on. But BB_Grimoire_Timer ( which is a value of 6 ) -23 would then equal -17, so GameHour will always be greater than BB_Grimoire_Timer. It will never get past that as far as I can see.
User avatar
Kevin S
 
Posts: 3457
Joined: Sat Aug 11, 2007 12:50 pm

Post » Sun May 01, 2011 8:32 pm

I thought it was something like that. How do I do it correctly though? I just can't think of how. I've been wracking my brains all day and it's just not coming to me.
User avatar
Brad Johnson
 
Posts: 3361
Joined: Thu May 24, 2007 7:19 pm

Post » Mon May 02, 2011 12:47 am

I think GameHour uses military time, so it's 0 at midnight, 1 at 1am and 13 at 1pm. You might want to cut out this check:

If ( GameHour > ( BB_Grimoire_Timer - 23.0 ) )


Keep the return in the main block and it should work.
User avatar
Love iz not
 
Posts: 3377
Joined: Sat Aug 25, 2007 8:55 pm

Post » Sun May 01, 2011 10:46 pm

But what if the variable is set when it == 23:00 hours or higher? It will never be 23.5 + 1 and never execute either.
User avatar
Sophie Miller
 
Posts: 3300
Joined: Sun Jun 18, 2006 12:35 am

Post » Sun May 01, 2011 10:17 pm

I don't know if this would work or not, but maybe you could turn it around to move the script on. Like:

If ( (BB_Grimoire_Timer + 1 ) > 24 )       set BB_Grimoire_Timer to ( BB_Grimoire_Timer - 24 )endIfIf ( GameHour < ( BB_Grimoire_Timer + 1.0 ) )	ReturnendIf


I think the logic works... but this can be tricky, eh?
User avatar
Britney Lopez
 
Posts: 3469
Joined: Fri Feb 09, 2007 5:22 pm

Post » Sun May 01, 2011 10:48 pm

Try this:

Begin BB_Grimoire_Globalshort doOnceIf ( doOnce == 0 )	if ( GameHour == 23 ) ;11pm		Set BB_Grimoire_Timer to 1 ;The affect is applied at 11pm and lasts until midnight.	else		Set BB_Grimoire_Timer to GameHour + 1 ;affect lasts for an hour.	endif	set doOnce to 1EndifIf ( GameHour < BB_Grimoire_Timer ) ;Has an hour passed?		Return ;No, so stop executing the rest of the script.EndifIf ( Player->GetSpell "grim_alteration" == 1 )	Player->RemoveSpell "grim_alteration"Elseif ( Player->GetSpell "grim_conjuration" == 1 )	Player->RemoveSpell "grim_conjuration"Elseif ( Player->GetSpell "grim_destruction" == 1 )	Player->RemoveSpell "grim_destruction"Elseif ( Player->GetSpell "grim_enchant" == 1 )	Player->RemoveSpell "grim_enchant"Elseif ( Player->GetSpell "grim_illusion" == 1 )	Player->RemoveSpell "grim_illusion"Elseif ( Player->GetSpell "grim_mysticism" == 1 )	Player->RemoveSpell "grim_mysticism"Elseif ( Player->GetSpell "grim_restoration" == 1 )	Player->RemoveSpell "grim_restoration"EndifMessageBox "You feel the effects of the grimoire wash away."Set BB_Grimoire_Timer to 0Set doONce to 0StopScript BB_Grimoire_GlobalEnd

User avatar
Victoria Bartel
 
Posts: 3325
Joined: Tue Apr 10, 2007 10:20 am

Post » Sun May 01, 2011 3:28 pm

Try this:

Begin BB_Grimoire_Globalshort doOnceIf ( doOnce == 0 )	if ( GameHour == 23 ) ;11pm		Set BB_Grimoire_Timer to 1 ;The affect is applied at 11pm and lasts until midnight.	else		Set BB_Grimoire_Timer to GameHour + 1 ;affect lasts for an hour.	endif	set doOnce to 1EndifIf ( GameHour < BB_Grimoire_Timer ) ;Has an hour passed?		Return ;No, so stop executing the rest of the script.EndifIf ( Player->GetSpell "grim_alteration" == 1 )	Player->RemoveSpell "grim_alteration"Elseif ( Player->GetSpell "grim_conjuration" == 1 )	Player->RemoveSpell "grim_conjuration"Elseif ( Player->GetSpell "grim_destruction" == 1 )	Player->RemoveSpell "grim_destruction"Elseif ( Player->GetSpell "grim_enchant" == 1 )	Player->RemoveSpell "grim_enchant"Elseif ( Player->GetSpell "grim_illusion" == 1 )	Player->RemoveSpell "grim_illusion"Elseif ( Player->GetSpell "grim_mysticism" == 1 )	Player->RemoveSpell "grim_mysticism"Elseif ( Player->GetSpell "grim_restoration" == 1 )	Player->RemoveSpell "grim_restoration"EndifMessageBox "You feel the effects of the grimoire wash away."Set BB_Grimoire_Timer to 0Set doONce to 0StopScript BB_Grimoire_GlobalEnd



It probably wouldn't make too much difference, but if the spell was cast at say 23:10 and you set the timer to 1 the effect will last almost 2 full hours because the first hour is 00:00
User avatar
Clea Jamerson
 
Posts: 3376
Joined: Tue Jun 20, 2006 3:23 pm

Post » Sun May 01, 2011 4:27 pm

I've actually been avoiding scripting because my head's just not in a logical frame of mind at the moment. I tend to oscillate between right-braininess and left-braininess.

I tried what you suggested, and the rest of the script is still not executing. I'm not sure what's going wrong here. The logic seems perfectly sound as far as I can tell.

Edit: Ah, I see you posted something new. I'll try that instead, except it's probably a bad idea to test it at exactly 11 pm, because GameHour is a float and it will probably never hit that exact number. I'll see about adjusting that and if it works.

Edit2: The new script almost working as intended. It removes the effect instantly between 11 pm or midnight though. I'll need to do some tweaking there.

Edit3: I did some tweaking to the script. This works exactly as intended now.

Begin BB_Grimoire_GlobalShort doOnceIf ( doOnce == 0 )	If ( GameHour >= 23 )		Set BB_Grimoire_Timer to ( GameHour - 23 )	Else		Set BB_Grimoire_Timer to ( GameHour + 1 )	Endif	Set doOnce to 1EndifIf ( GameHour < BB_Grimoire_Timer )	ReturnElseif ( GameHour >= 23 )	If ( BB_Grimoire_Timer < 1 )		Return	EndifEndifIf ( Player->GetSpell "grim_alteration" == 1 )	Player->RemoveSpell "grim_alteration"Elseif ( Player->GetSpell "grim_conjuration" == 1 )	Player->RemoveSpell "grim_conjuration"Elseif ( Player->GetSpell "grim_destruction" == 1 )	Player->RemoveSpell "grim_destruction"Elseif ( Player->GetSpell "grim_enchant" == 1 )	Player->RemoveSpell "grim_enchant"Elseif ( Player->GetSpell "grim_illusion" == 1 )	Player->RemoveSpell "grim_illusion"Elseif ( Player->GetSpell "grim_mysticism" == 1 )	Player->RemoveSpell "grim_mysticism"Elseif ( Player->GetSpell "grim_restoration" == 1 )	Player->RemoveSpell "grim_restoration"EndifMessageBox "You feel the effects of the grimoire wash away."Set BB_Grimoire_Timer to 0Set doOnce to 0StopScript BB_Grimoire_GlobalEnd


Thanks for you help! You've put me on the right track. :)
User avatar
Rachie Stout
 
Posts: 3480
Joined: Sun Jun 25, 2006 2:19 pm


Return to III - Morrowind