User talk:Cloventt

From GECK

Water Purifier Script

You'll probably notice that I've removed your "AAAwpscript" script from the Useful_Scripts page. I just thought that I'd let you know why I removed it, and give you a couple of pointers.

The script you added is essentially a short example of how to use conditional statements and a few commonly used functions. While this information is important, it's also very basic, so doesn't really belong on a page focussing on particularly useful scripts.

I notice that you've used a prefix of "AAA" on all forms that you've created with the GECK. While this is one way to make them easier to find, it is unnecessary. If you want your forms to appear at the top of the list, all you need to do is sort by formID (the formID column is hidden, just to the right of the editorID column). If you want to include a string in your editorIDs to identify them, I'd recommend making it unique to your mod and making use of the GECK's filter feature.

IsActionRef is only really useful in an OnActivate block when you need to have alternate code for different references. If you only want the code in the OnActivate block to run when a specific reference activates the scripted reference, then you can include that reference's editorID as a parameter of OnActivate:

Begin OnActivate player

When constructing expressions, it's important to think about whether or not you're transforming data in a meaningful way. In the context of conditional statements, all that matters is whether or not an expression evaluates to 0. If it does, then the code it contains won't run, otherwise the code will run.

For example, when calling GetItemCount, the only values that can be returned are integers that are greater than or equal to 0. This means that if GetItemCount returns a value greater than or equal to 1, it will be returning a non-zero value, so the following two conditional statements are equivalent:

if player.GetItemCount WaterUnpurified
if player.GetItemCount WaterUnpurified >= 1

Even though these two conditions have the same outcome, due to poor optimisation in the GECK's compiler the first option is more efficient than the second.

The same concept applies for functions that only ever return values of 1 or 0, like IsActionRef. For example, the following two conditions are equivalent, again with the first being more efficient:

if IsActionRef player
if IsActionRef player == 1

When using blocks of conditional statements (i.e. an "if" statement with accompanying "elseif" statements, and possibly also an "else" statement), conditions are evaluated from top to bottom until one evaluates to a non-zero value. If an "else" statement is reached, all previous conditions must have evaluated to 0 so the code within it will run without any more conditions being evaluated. Because of this, the following two segments of code are more equivalent, but the first is more efficient because only one expression will ever need to be evaluated:

if player.GetItemCount WaterUnpurified
	; ...
else
	; ...
endif
if player.GetItemCount WaterUnpurified
	; ...
elseif player.GetItemCount WaterUnpurified == 0
	; ...
endif

Whether the second condition in the second segment uses "== 0" or "< 1" doesn't matter, as 0 is the only value less than 1 that GetItemCount can return, and both operators have similar effects.

-- Cipscis 07:47, 4 March 2010 (UTC)

Personal tools