# 'S' update as of 4/12/11

New releases and general discussions.

### » Tue Oct 13, 2009 2:45 pm

Very useful stuff, Lucid!
B
16
S
6
G
6
Posts: 100
Reputation: 4,840

### » Wed Oct 14, 2009 8:13 pm

[size=85:nqxjjdin][/size:nqxjjdin]
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

[u:nqxjjdin]Get T[/u:nqxjjdin]
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
[url:nqxjjdin]http://dl.getdropbox.com/u/1013446/s/energybar.cap[/url:nqxjjdin]

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
[u:nqxjjdin]ranged seeded random.[/u:nqxjjdin]
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.

[url:nqxjjdin]http://dl.getdropbox.com/u/1013446/s/randrotgetloopt.cap[/url:nqxjjdin]

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
Spriter Dev
B
90
S
21
G
12
Posts: 3,246
Reputation: 16,548

### » Wed Oct 14, 2009 11:47 pm

thanks for this.
I get a runtime error when clicking in the last .cap and it closes?
B
135
S
65
G
17
Posts: 1,766
Reputation: 19,727

### » Thu Oct 15, 2009 12:00 am

[quote="alspal":k7oy5omz]thanks for this.
I get a runtime error when clicking in the last .cap and it closes?[/quote:k7oy5omz]
sorry, change the loopname on createtext to numloop instead of nummy
I changed the names at the last minute, and forgot to change it there...also, you can just redownload the cap at the same link, I fixed it

[size=85:k7oy5omz][/size:k7oy5omz]

This is a simple objecttype tutorial, to introduce objecttype arrays.
[url:k7oy5omz]http://dl.getdropbox.com/u/1013446/s/objecttypetutorial.cap[/url:k7oy5omz]

in this little game thing, you have a default green thing as your attack (space bar)
as you pick up items they are put in a queue, and each time you press space you use the first item in the queue, when you run out of special items, you fire your default again.

at the beginning you see I deactivated bullet movement...this was just so the objects would sit there until you picked them up.

on collision with blue I inserted tt("blue") into the array
tt stands for true type, you can of course choose a normal type, or a family to be added to the array. In this case, we don't want the type "blue" inserted into the array, we want the "true type" of the object, not the family type. this expression only works if there is an actual object, because of course there is no true type for the family itself.

so we insert the type at the "end"
and destroy the "blue" object

on "space bar" pressed
spawn the type at {"types"} (which is {"types",0})
and delete that entry in "types"

try out the cap, and try to understand the events.

now we are going to change it a little bit
we want to make lightning the new basic weapon, if we pick that up.

[url:k7oy5omz]http://dl.getdropbox.com/u/1013446/s/objecttypetutorial2.cap[/url:k7oy5omz]
on collision with "blue"
we use a condition from s
"is of object type"
we check if "blue" is of the lightning type. in this condition, you can also type in an arrayaddress for an object type or even the array address of an object using the o expression o({"objectarrayaddress"})

if it is of lightning type, we use the "new default value for array" action to make lightning the new default, and then we destroy the object we picked up

else, if it is not lightning type, we add it to the array the same as in the previous version

The next topic will be object arrays, then super arrays. then we will start to see full examples of complex projects, like inventory systems, and level editors, and we will see how s works to make these types of projects simple, and with few events.
Spriter Dev
B
90
S
21
G
12
Posts: 3,246
Reputation: 16,548

### » Thu Oct 15, 2009 1:05 am

this is great so far, you seem to make it easy to understand.
B
135
S
65
G
17
Posts: 1,766
Reputation: 19,727

### » Thu Oct 15, 2009 3:19 am

thank you, alspal, i edited it after you posted your first post, did you see I responded to your question about the crashed cap?

things are about start coming together, the next tutorial I have planned is on object arrays, as opposed to objecttype arrays. This post is not the full tutorial. It is a description of the problem we are going to solve with object arrays, and the example cap to do so. You may be able to figure most or all of it even without the tutorial.

so here's the problem.

create a weapon for an overhead shooter. You can left click on enemy ships to make them targets. Click the right mouse button to fire out drone missiles. The drone missiles should attack the targets one by one in the order you clicked them. if you fire more than one missile at a time, the missiles should take over the next target in line. No two missiles should ever attack the same target at the same time. After all targets are either destroyed, or currently being pursued by another drone missile, the drone missile should return to the mothership.

This can be accomplished in relatively few events, using s.
[color=#FF0000:1yg9669p][url:1yg9669p]http://dl.getdropbox.com/u/1013446/s/objectarray3.cap[/url:1yg9669p][/color:1yg9669p]
there's the cap, tutorial coming soon
have fun

[size=85:1yg9669p]a note on crashes:
if you click the same target twice you can make it crash. These are not random stability problems, I understand where the crash is coming from. I am working on ideal solution that will both maintain the power s and usability . The default system is the solution to the problem of trying to access values outside the array. This used to cause a crash, but I didn't want to return a meaningless value either. It turned out to be useful in another ways. The following problems also require solutions that both prevent the crash, but also make it obvious where something is going wrong, instead of just being a silent bug in your code. In the meantime, there are a few things that make s crash that can be avoided if you are aware of them.

1. typos. misspelling a name, forgetting an element to an address, or doing "this" instead of {"this"}
2. destroying an object, and then trying to do something with an object variable that pointed to it.
3. destroying an array, and then trying to access it.

also, everywhere you're expected to type an array address should begin like this {""} so the brackets are already there when you start, this goes the same for expressions.
Please let me know if you discover them missing anywhere.

Also, anywhere you can type in an object address, you should be able to use the name "in quotes" of any picked object. Please let me know if you discover anywhere this does not work.

thanks everyone who's helping me test this.[/size:1yg9669p]
Spriter Dev
B
90
S
21
G
12
Posts: 3,246
Reputation: 16,548

### » Fri Oct 16, 2009 2:53 am

Just tested out the the three .caps. I was getting lots of crashes, but I guess I had an old version. I re-downloaded today and they work great. These examples are cool. The .caps aren't complex either... I'll have to spend some time studying them though. I've really been wanting to make a few simple things with this plugin.. but just been so busy.

Anyway, nice work on the plugin and tutorials!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

### » Fri Oct 16, 2009 10:47 am

Is there and way to delete a container minimum and maximum value not just the value at the end of the container.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

### » Fri Oct 16, 2009 11:38 am

[quote="toralord":1veffbul]Is there and way to delete a container minimum and maximum value not just the value at the end of the container.[/quote:1veffbul]
yes, "end" is the last element in the array, you can also use any numerical index,0 being the firfst in the array. and i havent tested it much yet, but you can also specify a range of values as (min, max), such as (1,"end"), or (2,3), howver you must use the curly brackets, but my phone doesnt let me type those
Spriter Dev
B
90
S
21
G
12
Posts: 3,246
Reputation: 16,548

### » Fri Oct 16, 2009 1:07 pm

[quote="lucid":1fw0o3d4][quote="toralord":1fw0o3d4]Is there and way to delete a container minimum and maximum value not just the value at the end of the container.[/quote:1fw0o3d4]
yes, "end" is the last element in the array, you can also use any ,0 being the firfst in the array. and i havent tested it much yet, but you can also specify a range of values as (min, max), such as (1,"end"), or (2,3), howver you must use the curly brackets, but my phone doesnt let me type those[/quote:1fw0o3d4]

It dose not work.
It just delete the first numerical index now,
I need it to delete the index with the smallest value.
I need for example:

array {"1"}
[u:1fw0o3d4]Index = Value[/u:1fw0o3d4]
Index 0= 282
index 1= 438
index 2= 10
index 3= 169
index 4= 1000

Index 0 through 4 has there value.
The index with the smallest value is deleted.
That would be index 2.
Then the next and the next,etc.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

PreviousNext