Jump to content

Scripting compatibility does the first part but not the next


Cropzic

Recommended Posts

Hey. First ever post here so in advance, sorry if it's in the wrong sub or anything else i probably overlooked.

 

That out of the way, i have been editing a mod trying to learn a bit of GECK for a couple days and i managed to do what i wanted which was a huge relief and feeling of accomplishment!. Though, while adding some compatibility for other mods i started seeing a problem i've been trying to fix for the past 5 hours but my google skills is where it ended i guess. I am a complete potato at this coming from no experience in coding, modding or anything. I have installed tons of mods and figured out problems there and now the last week messed with game files and GECK.

 

The problem.

I have a script to add items from other esp's and esm's to a formlist, which works beautifully on the first section of the script but it seems to cut off after "endif"?

https://pastebin.com/KrSzqXmw There is a simplified version of the script i am using. It does get the info from "WeaponModsExpanded.esp" but not from the others, i have tried switching them around and the one at the top always works while the others doesn't.

 

 

Any help is highly appreciated. Still learning!

Link to comment
Share on other sites

When using IF, when you add more thant one sentence you shoud use { to start and } to close.

Thanks, Completely new to scripting and the brackets are sort of new to me, so where they belong exactly i am not entirely sure of. I'm on the google train so i'll report back :)

Link to comment
Share on other sites

When using IF, when you add more thant one sentence you shoud use { to start and } to close.

 

Please see the 'TIP: Best Practice - Encapsulation - Parens, Brackets, and Braces' (and the remainder of the entries) in the 'Scripting' section of the wiki "Getting started creating mods using GECK" article.

 

-Dubious-

I have been trying for over an hour now, but i just can't seem to understand their use with exactly why they are used i think. I have read up on brackets, braces etc and tried to find references without luck I have tried "Braces" multiple places, some broke the code, some didn't but nothing fixed the problem. I also tried playing with "Parens" but that led me unable to save my script no matter what i did.

 

I really come from extremely low knowledge in scripting to begin with. But as far as i understand from reading "Getting started creating mods using GECK" and googeling, i am supposed to "enclose" parts of the code like a "recipe dump" so that if x = true then open recipe and follow everything in it, if not then skip everything enclosed in "Braces". then the same for the other checks so in the end it does all the checks and in addition skips a lot of code it didn't need to go trough? Where in my example it only does the first one.

 

 

This might be a better way to ask. I am supposed to make this as a "checkpoint"

If IsModLoaded "mod.esp"
Let iModIndex := GetModIndex "mod.esp"
Then all of these to be read if the checkpoint was correct:
Let rForm := BuildRef iModIndex, 3260
AddFormToFormList modboxItemList rForm
Let rForm := BuildRef iModIndex, 3261
AddFormToFormList modboxItemList rForm

Which in addition will make the code go through all the checkpoints?

Link to comment
Share on other sites

A "conditional statement" (an "IF" is the basic form) consists of a "test condition" (e.g. "<this test must be 'true'>"), possibly followed by yet another "compound condition" which may be regarded as "Either/Or" or "And/Also MUST BE TRUE", all in a single statement which is then followed (in the GECK: on the next line) by the statements to be executed if the conditional statement is "true" in all respects.

For every "condition" you are checking to be "true" you are also (at least implying) there is a "false" condition that will occur if the test fails. The "conditional block" is made up of the "conditional statement" and is terminated by an appropriate "end" statement (i.e. for an "if" that is an "endif"). Some forms of conditional blocks (such as the "If") permit additional conditional tests to be conducted if the first fails (I.e. "ElseIf <condition>" statements) and a single (optional) "Else" (all is "false") section for when all earlier tests fail. This basic structure is more fully known as the "If ...( ElseIf) ... (Else) ... EndIf" (aka "If/Else") block where the parentheses indicated the statement is (optional). But for every "IF" there must be a concluding "ENDIF". (Notice the different use of case in these various examples. This is to show that case of the statements, commands, and functions is not important, but adopting a consistent pattern will help to make your script more readable. The case of "parameters" however, may be of importance so it's always worth paying attention to.)

So, you need the following structure for your "checkpoint test":

If IsModLoaded "mod.esp"
  Let iModIndex := GetModIndex "mod.esp"
  Let rForm := BuildRef iModIndex, 3260
  AddFormToFormList modboxItemList rForm
  Let rForm := BuildRef iModIndex, 3261
  AddFormToFormList modboxItemList rForm
; Else - do nothing
EndIf

If the test for "mod.esp" fails, the code that follows is skipped down to the "EndIf" statement and resumes processing with the next statement. If the test for "mod.esp" succeeds, then all the lines that follow (down to the "EndIf") are then executed in sequence.

 

I prefer to document implied "Else" statements with comments (the ";" causes everything else on the line to be ignored) in the code so I know that I did consider the implication and what I thought would happen if things turn out differently later on. The implied "Else" here is "do nothing if this mod fails to be loaded".

 

Note the use of indentation. This gets to be very important later on as you develop "nested conditions", such as:

If <condition1>
  some code if condition1 is true
  If <condition2>
    some additional code only if condition2 is true (in addition to condition1)
  ; Else - do nothing if condition2 fails
  EndIf
Else ; condition1 failed - condition2 was never tested
  code when condition1 fails
EndIf

Indenting the beginning and ending statements of "blocks" to the same level helps you ensure you have correctly matched them up.

 

The question of "encapsulation" arises with the conditional test in this instance. You could safely use "(parens)" to enclose the test, as in: 'If (IsModLoaded "mod.esp")', but in general a "function" (i.e. "IsModLoaded") followed by a single parameter (i.e. "mod.esp") doesn't require it unless you are getting errors. Functions that require more than a single parameter usually do need encapsulation; the type of enclosing characters depending upon the type of function. "(Parens)" are most common and generally safest when in doubt.

 

Finally, note that "let <var> :=" is NVSE syntax. You must have NVSE loaded when running the GECK (use the GECK Extender: link under "Programs and Tools" in the "Getting Started" article) and specify it as a requirement for your mod if you publish it or you will get a compiler error and your users will not be able to get the mod to function correctly without it. Don't let that stop you as almost everyone has it installed anyway, but it is important to realize.

 

-Dubious-

Link to comment
Share on other sites

A lot of this new fangled scripting that goes beyond Fo3 and Fose is greek to me.

So this is probably off base , or I'm failing to understand it myself.

 

But it seems you need an off switch per "If" statement that comes up as true , then does it's thing. Because with only 2 variables to use. They are always in use from the first "If"

Which is the out put per frame read.

So I think you need some way to tell it not to execute that which has already been executed.

 

Just a thought using my seems to me method :confused:

Link to comment
Share on other sites

A lot of this new fangled scripting that goes beyond Fo3 and Fose is greek to me.

So this is probably off base , or I'm failing to understand it myself.

 

But it seems you need an off switch per "If" statement that comes up as true , then does it's thing. Because with only 2 variables to use. They are always in use from the first "If"

Which is the out put per frame read.

So I think you need some way to tell it not to execute that which has already been executed.

 

Just a thought using my seems to me method :confused:

I think we are on the same page, i am currently playing around with the golden info @dubiousintent posted. However as you mentioned after playing with the info and learning from it which was excellent, i still haven't solved my problem. Unless i am completely blind (May be the case) Because as an experiment to learning what Dubious said, i tried it on my "semi-functional" script to put learning into practice but the problem persist. It still only does the first "IF" and not the others.

 

 

 

Also, to clarify. I am using NVSE and JIP after going trough the (Fix this flood of errors) Stage of geck which was, fun. So i should be fine with tools, i think it just comes down to pure knowledge.

 

Second clarify. English is my second language, so to be more direct, I have multiple "IF"'s, but only one works.The total script consists of 3 "IsModLoaded"'s but the amount of stuff it adds to FormList's makes the total script 1000 characters long. (And yes it took a while writing and converting FormID's from Hex to decimal for each item, which there probably is a way easier method to doing x)) i digress...

Link to comment
Share on other sites

Well to better clarify what I was saying ...

 

I think the first "If" is continually coming back as true , therefore it continues to set the variables by it's command lines. Not letting the other "If" 's do their code execution.

 

Maybe you need to use an array variable ? But that is delving into IDK territory for me.

 

So as a thought experiment ... what if you had a unique set of variables declared up top for each "If" , then set and used only in its "If" block ?

 

Or you make a 3rd variable (an Int one) That is checked and set at each if , like so ...

 

If iCheckCount == 0

Set iCheckCount to 1

If IsModLoaded "mod.esp"

;Do stuff

endif

 

If iCheckCount == 1

Set iCheckCount to 2

If IsModLoaded "mod.esp"

;Do stuff

endif

 

If iCheckCount == 2

Set iCheckCount to 3

If IsModLoaded "mod.esp"

;Do stuff

endif

 

endif

endif

endif

 

END

~~~~~~~~~~~~~~~~~~~~~

 

I am unfamiliar with the "Begin Function" block , so not really sure about how it executes.

Link to comment
Share on other sites

Well to better clarify what I was saying ...

 

I think the first "If" is continually coming back as true , therefore it continues to set the variables by it's command lines. Not letting the other "If" 's do their code execution.

 

Makes sense to me if this is the case.

 

 

So as a thought experiment ... what if you had a unique set of variables declared up top for each "If" , then set and used only in its "If" block ?

 

Or you make a 3rd variable (an Int one) That is checked and set at each if , like so ...

 

If iCheckCount == 0

Set iCheckCount to 1

If IsModLoaded "mod.esp"

;Do stuff

endif

 

If iCheckCount == 1

Set iCheckCount to 2

If IsModLoaded "mod.esp"

;Do stuff

endif

 

If iCheckCount == 2

Set iCheckCount to 3

If IsModLoaded "mod.esp"

;Do stuff

endif

 

endif

endif

endif

 

END

~~~~~~~~~~~~~~~~~~~~~

This made me really hopeful. But after testing it, Even with mix-matching the numbers. Now ONLY the one with "if iCheckCount == 0" works. I am beyond confused at this point. Code is hard, but certain things makes sense. When they make this much sense and yet doesn't work... It has to be me doing something wrong here. So here is the entire script i am working on right now.

Right before posting this i even tried to use 3 int for modinex. So, IModIndex, IModIndex2 and IModIndex3. After that failed, i did the same with rForm. Still no damn luck. But thank god for Notepad++.

 

 

And here is the part from the main script that runs it:

short iMenu

Begin MenuMode
	If iMenu > 0
		If iMenu == 1
			If GetActiveMenuMode == 1002
				; Upon opening the menu, check load order for compatibility. Once per gameload.
				If GetGameLoaded
					call modboxFnCompatibility
				Endif

As of now i am blank. I haven't tried "array variable" as of yet, nor do i understand it. But at least, in my eyes after feeling like i've been hand holding the script trough. With my mindset, every time i tried these things i'm like "No way it wont work now" Yet it does not. Again, i have to be missing something.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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