Jump to content

scripting help


Wyked

Recommended Posts

couple questions:

 

Is there a script function for "LoopUntil" or something similar?

is there a script function to get the itemhealth of armor the player has on them or has equipped?

how do you set a terminal to run a script in the runscript box? (Right now i have to enter my entire script inside the box to get it work, instead of just calling the script to run)

Link to comment
Share on other sites

You can do loops in mainly two ways:

1) The ugly way: The intended script is on an item (and you keep adding the item), or is in an activator and you keep calling activate 1, or is on a quest and you keep calling stopquest/startquest.....

 

2) You use fose, you got a label and a goto function.

 

Getting health of items in the player's inventory is tricky, if it's equipped you can use GetEquippedCurrentHealth from fose. Otherwise you're owned.

 

3) Attach the script to an activator (and call activate 1), or put it on a gamemode and/or menumode block on an object (and additem it to the player), or other similar workarounds.

 

 

Fose documentation page: http://fose.silverlock.org/fose_command_do...edCurrentHealth

Link to comment
Share on other sites

If you use stages you can use a variable that counts how many passes, which would act as a "Do-Until". I use them quite a bit so I do not have to rewrite code for every step. But it would only work in either a GameMode or MenuMode block, or any block which runs each frame. It would work somthing like this:

 

Int LoopTill
Int Stage

If (Stage == 0)
Set LoopTill 0
set Stage to 1
EndIf
If (Stage == 1)

<Do Somthing that you want to repeat>

Set Stage to 2
EndIf
If (Stage == 2)

If (LoopTill < 5)
	set Stage to 1
	set LoopTill to LoopTill + 1
Else
	set Stage to 3 ;Move to next Stage after "Stage 1" has been repeated 5 times
EndIf
EndIf

 

Not only is that safer then using a Goto Loop, It keeps your code organized. You can actually merge Stage 1 and 2 in this example, but It's more organized if you plan on using

alot of conditions.

Link to comment
Share on other sites

Alundaio, i fail to see the different in safety between your method and a label-goto, it's pretty much exactly the same logic-wise.

On the other hand, it runs one lap per frame, or rather, since it's on a quest, one loop per the defined script delay of the quest. This method may be 'too slow' depending on what you want to do (activate 1 loops and fose goto-label loops work on the exact same frame)

Link to comment
Share on other sites

Well, the use of Goto has always been a sign of bad programming structure. It will create "Spaghetti Code" because it will litterally JUMP to that point whether it's backwards or forwards in the code. It is not exactly the same, unless FOSE's Goto-Label is just a Fake function that mocks the example I wrote. There are alot of different things I can say about goto, but, I assume from the great help you usually give the community in coding you would know all the bad things about looping with a Goto statement.

 

This method is safe because it is highly readable and more controlled, unlike Goto statements, which can cause confusion and may easily lead to infinite loops.

 

I don't know what kind of programming background you have, but In my C++ courses and books I have learned that Goto was used in the primitive days of coding and shouldn't ever be used in practice.

 

Also, I assume from the question that this fellow is new to scripting in Fallout and therefore probably isn't using FOSE at this current time.

 

 

 

*EDIT* But you are right, it does depend on what you are trying to achieve in your script.

Link to comment
Share on other sites

In the background, every loop structure IS a goto, these however are more readable and are often optimized by the compiler. It is a bad form to use goto when you have proper looping functions for these reasons, and using goto as an escape inside a loop function is frown upon and often a sign of bad design.

 

This, however, is not the case with fallout script code, there are no looping functions whatsoever, the closest two things that can be done are using the frame-bound blocktypes, and "calling" a script by means of adding, activating or otherwise loading into memory another object that haves the desired script.

 

Using the later to make a loop is unaesthetic at best, and ultimately an unnecessary bloat of the base label-goto code. Using the former to make a loop results in the exact same thing, tho with the disadvantages and advantages of being spread through the frames instead of done in just one. The base label-goto code i am referring to is this:

 

<starting point or label>
<code to be repeated>
If (Status != <Stop Condition>
<call a repeat>
EndIf

 

You can change the parts with additem + removeme or start & stop a quest or call activate 1 or change the quest's stages, but it is ultimately an overdressing of the same old and tried base label-goto code. Using fose label and goto is ultimately more efficient as it does not involve loading an extra object into memory, and it is more clear and readable than any of the other options.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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