Jump to content

Scripting problem is driving me insane


amcclell

Recommended Posts

I'm having a very annoying bug with a script I'm working on. It's a Begin GameMode type quest script, attached to a quest set to be active on start (You know the usual "Background handler" kind of quest). The problem is, the script seems to only run once, when I load the game, and then never again. I can't tell if it's a bug with my game or the script or what, but it's very annoying. Everything else I'm running works as it's supposed to, but this script seems to refuse to behave. Here is the script in question:

 

ScriptName AddictionToughOut

; All Addiction functionality goes here.

float BuffoutT
float UJetT
float AlcoholT
float AntNectarT
float JetT
float MentatsT
float MorphineT
float PsychoT
float StimpackT
float RadXT
float TwoCIT
float AmphT
float BenzoT
float CocaineT
float DXMT
float NoDozeT
float MethT
float PCPT
float RadAwayT
float SativexT
float TobaccoT
float QNukaT
short Cleansed
float CleanT
float FailT
short tempadd

Begin GameMode

; Addiction Withdrawal is handled here

Set Generic.Addicted to 0
If Player.HasMagicEffect AddictionEFFECT && Cleansed == 0
	Set Generic.Addicted to 1
EndIf

set tempadd to Player.IsSpellTarget WithdrawalRadX
ShowMessage Debugger GameDaysPassed Cleansed RadXT tempadd

If Cleansed == 1 && GameDaysPassed - CleanT >= 1
	Player.RemoveSpell WithdrawalAlcohol
	Player.RemoveSpell WithdrawalAntNectar
	Player.RemoveSpell WithdrawalBuffout
	Player.RemoveSpell WithdrawalJet
	Player.RemoveSpell WithdrawalMentats
	Player.RemoveSpell WithdrawalMorphine
	Player.RemoveSpell WithdrawalPsycho
	Player.RemoveSpell WithdrawalQuantumNukacola
	Player.RemoveSpell MS09WithdrawalUltraJet
	Player.RemoveSpell XanderRoot
	Player.RemoveSpell WithdrawalRadX
	Player.RemoveSpell Withdrawal2CI
	Player.RemoveSpell WithdrawalAmph
	Player.RemoveSpell WithdrawalBenzo
	Player.RemoveSpell WithdrawalCocaine
	Player.RemoveSpell WithdrawalDXM
	Player.RemoveSpell WithdrawalNoDoze
	Player.RemoveSpell WithdrawalMeth
	Player.RemoveSpell WithdrawalPCP
	Player.RemoveSpell WithdrawalRadAway
	Player.RemoveSpell WithdrawalSativex
	Player.RemoveSpell WithdrawalTobacco
	Player.RemoveSpell AddictionClean
	ShowMessage AddictionCuredMessage
	Set Cleansed to 0
EndIf

If Player.IsSpellTarget WithdrawalBuffout && GameDaysPassed - BuffoutT >= CleanTimeBuffout
		Player.RemoveSpell WithdrawalBuffout
		ShowMessage CleanBuffout
EndIf
(Snipped out a bunch of checks for other chems, they're all identical to this one)

End

 

Basically, it's the code from Wasteland Survivor for letting chem addictions wear off on their own, which I'm adapting for FWE. The part that's driving me insane is that I've run this before and it worked fine. Hell, as far as I can tell, it still works fine when the conditions are met. The problem is that it just doesn't want to keep running like it's supposed to.

 

Is this an issue with my game or is it just something wrong with my code?

 

*Edit*

 

Just to make everything clear, here is the effect script that's run by chems when they're consumed:

 

Scn ChemBuffoutScript

Begin ScriptEffectStart

If Addiction.Cleansed == 1
	Player.RemoveSpell AddictionClean
	Player.AddSpellNS AddictionFail
	ShowMessage AddictionFailMessage
	Set Addiction.FailT to GameDaysPassed
EndIf
Set Addiction.Cleansed to 0

End

Begin ScriptEffectFinish

If Addiction.Cleansed == 0 && IsSpellTarget WithdrawalBuffout
	Set Addiction.BuffoutT to GameDaysPassed
EndIf

End

Link to comment
Share on other sites

Since I was not able to find an error from simply looking at it, you should first insert a debug message right at the start, and one at each exit point to confirm that the script ran through completely the first time.

If yes, it should run again up to some point where eventually theres a logic mistake.

 

If not (start debug message, but no end debug message), there a runtime error somewhere. This means that your script will stop executing, and it can be caused by a number of reasons.

Link to comment
Share on other sites

I'm having a very annoying bug with a script I'm working on. It's a Begin GameMode type quest script, attached to a quest set to be active on start (You know the usual "Background handler" kind of quest). The problem is, the script seems to only run once, when I load the game, and then never again. I can't tell if it's a bug with my game or the script or what, but it's very annoying. Everything else I'm running works as it's supposed to, but this script seems to refuse to behave. Here is the script in question:

 

ScriptName AddictionToughOut

If Player.IsSpellTarget WithdrawalBuffout && GameDaysPassed - BuffoutT >= CleanTimeBuffout
		Player.RemoveSpell WithdrawalBuffout
		ShowMessage CleanBuffout
EndIf

End

I haven't seen any documentation on the order of operations in this scripting language, but you might try using parentheses to make sure this is happenning:

If ((Player.IsSpellTarget WithdrawalBuffout) && (GameDaysPassed - BuffoutT) >= CleanTimeBuffout))

and not this:

If ((Player.IsSpellTarget WithdrawalBuffout && GameDaysPassed) - BuffoutT >= CleanTimeBuffout)

Link to comment
Share on other sites

I'm having a very annoying bug with a script I'm working on. It's a Begin GameMode type quest script, attached to a quest set to be active on start (You know the usual "Background handler" kind of quest). The problem is, the script seems to only run once, when I load the game, and then never again. I can't tell if it's a bug with my game or the script or what, but it's very annoying. Everything else I'm running works as it's supposed to, but this script seems to refuse to behave. Here is the script in question:

 

ScriptName AddictionToughOut

If Player.IsSpellTarget WithdrawalBuffout && GameDaysPassed - BuffoutT >= CleanTimeBuffout
		Player.RemoveSpell WithdrawalBuffout
		ShowMessage CleanBuffout
EndIf

End

I haven't seen any documentation on the order of operations in this scripting language, but you might try using parentheses to make sure this is happenning:

If ((Player.IsSpellTarget WithdrawalBuffout) && (GameDaysPassed - BuffoutT) >= CleanTimeBuffout))

and not this:

If ((Player.IsSpellTarget WithdrawalBuffout && GameDaysPassed) - BuffoutT >= CleanTimeBuffout)

 

I'm pretty sure this isn't the issue - I'd worried about that with another mod in the past, but it turned out not to be the problem, and the condition was much more complex than this one. Besides, all this would do is create a situation where the if statement would execute or not execute when I don't want it to - which isn't the issue I'm having. The issue is that stuff isn't executing more than once even when it's just in open space just after the Begin GameMode line (And thus it should execute on every pass). It's possible this might be causing a runtime error, though, since I tried what Schlangster suggested and it is indeed dying right around the point when those statements start. I'm still getting used to GECK not complaining about syntax except for flagrant errors like an unterminated If or a non-existent variable. It's kind of scary when C is more user-friendly than something.

 

*Edit* Aha! I found it. It wasn't order of operations, but in the process of adding the brackets I found the error - One of the (20ish) checks was missing a && in the middle, so apparently If Player.IsSpellTarget WithdrawalBuffout GameDaysPassed - BuffoutT >= CleanTimeBuffout was good enough for the compiler but not the runtime. As soon as I fixed that, the script starting running how it was supposed to. I imagine you probably would have spotted that if I'd posted the entire script but at the same time I didn't want my post to be a huge wall of code that nobody wanted to read.

Link to comment
Share on other sites

Although parenthesis are not needed on most cases, it is a good habit to use them anyway as well as commenting, as they together make debugging the scripts a LOT easier. Also if you have ever suspect on leaving FO3 modding behind, it will be a lot easier for other people to take up your mod and keep it working/compatible.

 

The comments are ignored anyway when GECK compiles the script, so they are there only for easier reading.

 

Also keeping the Script as simple as possible is considered a good habit.

 

The real problem in the script is, that you are using the GameDaysPassed special variable, which shows the days passed from the beginning of the game, not from when the script was run, so it will ALWAYS be higher than 1 after the first game day. I also didn't see anywhere a set command for CleanT?

Link to comment
Share on other sites

Although parenthesis are not needed on most cases, it is a good habit to use them anyway as well as commenting, as they together make debugging the scripts a LOT easier. Also if you have ever suspect on leaving FO3 modding behind, it will be a lot easier for other people to take up your mod and keep it working/compatible.

 

The comments are ignored anyway when GECK compiles the script, so they are there only for easier reading.

 

Also keeping the Script as simple as possible is considered a good habit.

 

The real problem in the script is, that you are using the GameDaysPassed special variable, which shows the days passed from the beginning of the game, not from when the script was run, so it will ALWAYS be higher than 1 after the first game day. I also didn't see anywhere a set command for CleanT?

 

The set command for CleanT is in a doctor script I didn't post, since it was working fine. All the comparisons are between a variable that's been set to GameDaysPassed at a previous time, and the current value of GameDaysPassed. That's why they have secondary conditions restricting the comparison so that it's only true when the values of *T are meaningful (Since, like you said, they're going to always evaluate as true because GameDaysPassed will be much higher than the starting value of the variables, which I believe defaults to 0).

Link to comment
Share on other sites

Quest script variables keep the values between game sessions, so you need to reset them before adding not cumulative values (it is not the case in your script but may be worthy warning). In a script that only set variables it isn't a problem, once the coder does not rely the value will be reset at each script call.

 

Quests are defined by stages, if someway the quest is stopped it will need a direct StartQuest command from somewhere, you should check your quest is active so it's script is too.

 

To grant the quest is active every time you initiate a game session it need to have the "Start Game Enabled" else it will run once or never (you already did it).

 

Quest script run at intervals of seconds instead each frame like reference scripts.

 

The advise to use parenthesis in complexes conditions is a very sound one.

 

These are some basics about quest scripts and the quests itself that may help to understand what may be happening, mainly if the quest and it's script does have external controls.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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