Jump to content

Snippet of Code Not Working as Intended


GimmeBackMyMoney

Recommended Posts

I made some changes to the Water Purifier script from Tales From The Burning Sands (a copy of the entire script can be found here: https://pastebin.com/LMiBDS5Z). This was to get it to work with Arwen's as well as purify irradiated water.

 

I want to draw attention to this block under OnActivate:

 

  1. if PurInstalled == 0
  2. if player.getitemcount IrradiatedWaterUnpurified >= 4
  3. player.removeitem IrradiatedWaterUnpurified 4 1
  4. player.additem ArwenEmptyDirtyWaterBottle 3
  5. aaq1waterspray.enable
  6. set x1 to 1
  7. else if player.getitemcount ArwenWaterDirty >= 3
  8. player.removeitem ArwenWaterDirty 3 1
  9. player.additem ArwenEmptyDirtyWaterBottle 2
  10. aaq1waterspray.enable
  11. set x1 to 1
  12. else if player.getitemcount WaterUnpurifiedHalf >= 4
  13. player.removeitem WaterUnpurifiedHalf 4 1
  14. player.additem ArwenEmptyGoodWaterBottle 3
  15. aaq1waterspray.enable
  16. set x1 to 1
  17. else if player.getitemcount WaterUnpurified >= 2
  18. player.removeitem WaterUnpurified 2 1
  19. player.additem ArwenEmptyGoodWaterBottle 1
  20. aaq1waterspray.enable
  21. set x1 to 1
  22. endif
  23. endif

 

When I have at least three ArwenWaterDirty in my inventory, this block executes properly. However, if I have no ArwenWaterDirty and any number of Good Waters (base game's Dirty/Unpurified Water), the code ALWAYS executes the second if block i.e. I get two empty dirty water bottles while the amount of Good Water remains unchanged, INSTEAD of getting a single empty good water bottle and having the total count of Good Water decrementing by 2.

 

I added a few debug lines to the second block to print out how many ArwenWaterDirty I have and it returns 0, yet it would appear this condition is evaluating as true regardless.

 

Could anyone help me, even if it involves making me look stupid and pointing out an obvious error I've made? Because it's driving me batty.

 

Thanks in advance.

Link to comment
Share on other sites

The scripting problem that jumps out at me ... Is "else" & "If" should not be separated.

 

It should be "elseIf"

 

Or elseif , eLseIF, ElsEiF, ... the case of the letters matter not. But one word does.

 

Because remember Else and IF can be used separately ... hence confusing the code crunching engine.

Edited by Mktavish
Link to comment
Share on other sites

...and it's worked a treat.

 

You're a champ, thanks for pointing that out. I couldn't remember whether or not you were supposed to put a space in between them, and assumed it would be parsed as the same as long as the "else" and "if" are on the same line because I never got any GECK errors.

 

Now I'll have to go through all other scripts I've created and edited, but this will explain some of the peculiar behaviour I've encountered.

 

Thanks again!

Link to comment
Share on other sites

Suggest you consider using the (free) "Notepad++" as your editor with "NotepadPlusPlus Syntax Highlighter" by DoctaSax as an imported "user defined language" addon. That will catch most similar syntax errors automatically for you. It will also popup a list of suggested keywords as you start to type, which you can select and then add with the <tab> key.

 

-Dubious-

Link to comment
Share on other sites

 

I couldn't remember whether or not you were supposed to put a space in between them, and assumed it would be parsed as the same as long as the "else" and "if" are on the same line because I never got any GECK errors.

 

No ... never a space

 

When else and if are to be used together ... always use "elseif"

 

Other wise its just useing "else" by itself

 

"IF" ofcourse is definitely used by itself , and must be !!!

Link to comment
Share on other sites

ElseIf is used when there are multi things that happen after X = 1

 

 

ElseIf X= 2

Do this

ElseIf X=3

Do that

ElseIf X=7

Go F U self

 

See , it is various outcomes.

Edited by Mktavish
Link to comment
Share on other sites

Yeah, my understanding was you never put a space in between else and if, I guess I didn't think much of it this time because it got past the GECK's syntax checks.

 

That NP++ feature will come in handy so thanks for linking that, dubious.

 

Thank you both for the help.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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