click here to download latest version (10/14)
<img src="http://dl.getdropbox.com/u/1013446/s/s.png">
ok, I apologize for the delay, but there is a silver lining. The superstructure portion of the plugin for download above is much closer to complete.
We are going to have a different type of tutorial today, that will be a crash course in everything s over a wide array (get it?) of ideas and syntax. I won't be walking through every detail, but there should be enough information to get you on your way. Anything anyone needs help on, or can't get to work properly, we'll delve more deeply into those areas in the tutorials that follow.
OK, so this tutorial assumes you've read, and understand, the first two tutorials.
We've created string arrays, and added values, and deleted values.
Number arrays are used in the same ways, and we will be looking at primarily numerical examples as we complete the remainder of the basic array features. The examples in this tutorial require features from the new version of the plugin linked above.
First we will learn 2 new math expressions included in s
Get T
abbreviated t(min,max,amount)
this will generate a value between 0 and 1 that represents the ratio between min and max that amount is.
it would return 0 if amount was equal to min,
1 if amount was equal to max. and 0.5 if amount was halfway between the two.
this t value has many uses.
here's a simple example
First we will see an example of an energy bar that shows how far across the screen we are
http://dl.getdropbox.com/u/1013446/s/energybar.cap
the t value is also the value t in many equations, such as interpolating functions, and trigonometric functions. (ie. lerp and cosine)
there is a special version of this lt, short for loop t, we will use later in this tutorial
another math expression in s is
ranged seeded random.
the expression is s.rand(min,max) and returns a random number between min and max
there is an action to Seed Random
if you will need to repeat the exact same sequence of random numbers again
seed the random with a known value (this can be a random number that you save in a variable for later use)
after seeding once you generate random numbers as normal
if you needed the randomness to reset you could reseed the random with the numbervariable you created. this will start the same exact random sequence you had the first time. you can do things like generate the same random starfield each time a game loads up, or have a rewinded scene generate the same randomized values for ai decisions, or in a custom particle generator.
Next we will move onto one feature of arrays we didn't cover in the last lesson. the 'last element expression'
you will find it as Number Array size -1, String Array Size -1, etc when you double click s for the expression list
These expressions return the index of the last element in an array, Since s is 0 indexed, this is the array size-1
the expressions are:
ole({"object array address"}) index of last element in an object array
otle({"objecttype array address"}) index of last element in an objecttype array
sle({"string array address"}) index of last element in an string array
nle({"number array address"}) index of last element in an number array
sule({"super array address"}) index of last element in an super array
now that we've covered the basic expressions for arrays,
let's move on to actions and conditions.
First the other basic actions we haven't learned yet that apply to every type of array.
One of them is rotate array. This will shift every member of the array the specified amount of times forward or backward, and have anything that shifts off the end of the array wraparound to the other side, for instance:
A B C D
if you rotated this 1 it would become
D A B C
if you rotated ABCD -1 it would become
BCDA
swap array values swaps two values with eachother
given ABCD, if you were to swap 0 and 3, you would get:
DBCA
Delete Array destroys the entire named array, you cannot add to the array again, because it no longer exists
Clear Array deletes all the elements in an array, but not the array itself.
Now onto conditions,
Is Contained in allows you to specify a value. if that value is in any of the elements of the array, the condition is true,
now, we are moving onto the For Each conditions
These are similar to other For Each conditions in construct. They loop once for each elements in the specified array.
There are a few important things to know unique to S's for each conditions.
The first is, these are named loops, and you can nest them within eachother.
you can use the name of the loop for several things
you can do
lle("loopname")
loop last element
this gives you the largest index the loop will loop to. It is the size - 1 of the array the loop is looping through
li("loopname")
loop index, this gives you the current index in the loop
also when addressing something from the loop, you can use a special key character "l" to automatically specify the array the loop refers to. for instance
loopname: "myloop" For Each Number in {"this","that","number"}
if you wanted to get the number contained at the 0 index of "number" while in the loop, instead of:
n({"this","that","number",0})
you could just write n({"l","myloop"})
we haven't worked with addresses longer than one word, but this will come in handy as you construct larger and more complex structures. Also, these work recursively, you can specify the array to loop through using the {"l","loopname"} notation.
here is an example of a simple app that uses the ranged random function, and loop t function (s.lt("loopname") - this is the equivalent of t(0,lle("loopname"),li("loopname")), basically a t value for the progress of the current loop)
this example also uses the rotate array action, you can toggle that off, and try the swap array function as well
to use this cap simply press the left mouse button to add extra random numbesr to the array.
right mouse button rotates the array.
http://dl.getdropbox.com/u/1013446/s/randrotgetloopt.cap
sorry for the delay in tutorials. I'm beginning work on the object and objecttype array tutorials, and that's where you'll start to see some of the real power of s
after that will be the super tutorial, and at that point you will have enough information to use 's's superstructure functionality to the fullest, and I will move on to complete the rest of the plugin