Thyme Tutorial: The Basic and Advanced Techniques
Thyme Tutorial: The Basic and Advanced Techniques
Thyme Tutorial: The Basic and Advanced Techniques
Thyme Tutorial
Thyme Version: 1.5.6
Last Update: 2009
Thyme Tutorial 2
2. Type a name for your variable, like Power or Example or Ex123 or P0W3R.
5. Check you haven't made any mistakes, it should look something like Power = 6.
6. Press Enter.
NOTE: If you are putting more than one variable declaration in a code,
separate them with ;
What is an integer?
An integer is a whole number, which has no decimal part, it can be used in list indices.
What is a float?
A float is a floating point number, which has a decimal part, it can be used in most situations, if
the number is more than 3.39e+37 it will be treated as +inf.
What is a string?
A string is a group of letters and numbers, strings can contain spaces, new lines (\n), and a
range of other things, (like tab spaces (\t)), strings are mainly used in textures, text boxes and a
few other things.
A boolean value is a true or false value, boolean values can be used for if structures, and a
whole lot of variables.
What is an identifier?
An identifier is the name of your variable, like in "Example = 60.7", "Example" is the identifier
in that statement.
Example:
Code:
NumberOfApplesNeeded = 3;
NumberOfApples = 0;
Thyme Tutorial 5
Tutorial 2: Scene.my.*
What is Scene.my.*?
Scene.my.* is a serialised (saved to file with the rest of the scene) structure, that you can
declare variables in, it is favourable to objects not in the scope, and offers quite a few benefits,
most scenes on algobox will be found to use these variables as opposed to the normal
variables.
6. Check you haven't made any mistakes, it should look something like Scene.my.Variable12A =
2.
7. Press Enter.
What is an expression?
An expression is basically an action, for example, in the code: "Scene.my.Variable12A = (2 +
5)", "= (2 + 5)" is the expression.
Example:
John wants to know how many apples Thomas needs, Thomas knows he needs 3 apples, and
Thomas currently has no apples, Thomas has to save these to a scene and put it on algobox.
Thyme Tutorial 6
Code:
Scene.my.NumberOfApplesNeeded = 3;
Scene.my.NumberOfApples = 0;
Thyme Tutorial 7
Example:
Thomas knows he needs 3 apples, and he also knows how many apples he has, which is none.
Code:
Scene.my.NumberOfApplesNeeded := 3;
Scene.my.NumberOfApples := 0;
Thyme Tutorial 8
Tutorial 4: Structures
What are structures?
Structures are objects which contain variables, or, can if the user tells them to. The most
commonly used structure is most likely Scene.my, which is contained in the structure Scene.
Are there any structures that don't contain any variables to start
with?
Yes, Scene.my is a structure, and it begins without any variables in it, you can add variables as
you want (Tutorial 2).
Example:
Thomas knows he needs to get 3 litres of milk from the Scene. store, and 2 litres of milk from
the Keys. store, Thomas has no milk at the moment.
Code:
Scene.LitresOfMilkNeeded = 3;
Scene.LitresOfMilkGathered = 0;
Keys.LitresOfMilkNeeded = 2;
Keys.LitresOfMilkGathered = 0;
Thyme Tutorial 9
Example:
Thomas wants to buy the following items: Bread, Milk, Apples, Bananas, Cheese and Ice
Cream, he needs to buy the following quantities: 1 loaf, 3 litres, 4, 3, 500g, 4L. At the moment,
he has none of the things in the list.
Code:
Thyme Tutorial 10
Scene.my.ShoppingQuantities = [1,3,4,3,500,4];
Scene.my.ShoppingProgress = [0,0,0,0,0,0];
John also needs to buy the same items, but orders it differently.
Code:
Scene.my.ShoppingList =
[["Bread",1,0],["Milk",3,0],["Apples",4,0],["Bananas",3,0],["Cheese",500,0],["Ice Cream",4,0]];
Thyme Tutorial 11
What is an action?
An action/function can be a modification to another variable permanently, or, could print
something, or calculate a value.
9. Check you haven't made any mistakes, it should look something like
Scene.my.FunctionExample = {Scene.my.VariableExample1 =
Scene.my.VariableExample1 + 1}.
10. Press Enter.
Example:
Thomas always needs to keep 5m^3 of space in his cupboard, he only stores apples in his
cupboard (we assume that each apple takes up 1m^3 (which is quite a bit for an apple )).
Code:
Scene.my.NumberOfApples = 3;
Scene.my.SpaceNeededAvaliable = {Scene.my.NumberOfApples + 5}
Thomas makes sure he keeps the space in his cupboard, but, every now and again, he'll buy a
new cupboard, which means that his capacity for apples goes up.
Code:
Scene.my.NumberOfApples = 3;
Scene.my.NumberOfCupboards = 2;
Scene.my.BuyNewCupboard = {Scene.my.NumberOfCupboards =
Scene.my.NumberOfCupboards + 1};
Thyme Tutorial 13
I typed the correct number for the function, but it didn't execute,
how can I make it?
Action Arrays work differently to normal arrays, you require one set of brackets ("()") to
execute the function.
Thyme Tutorial 14
Example:
Thomas has a set of tests he has to do based on how big each apple he picks is, which
determines how it is categorised, and how much it is going to cost, if an apple is under 1dm^3
it is placed in the category "Small", small apples cost $3.50, if it is above 2dm^3 it is placed in
the category "Medium", medium apples cost $2.50 per dm^3 ($5), if it is above 3dm^3 it is
placed in the category "Large", large apples cost $1.50 per dm^3, Thomas wants to know how
much the apple is whenever he tests it.
Code:
Scene.my.TotalValueOfApples = 5.0;
Scene.my.AddAppleCost = [{},{Scene.my.TotalValueOfApples = Scene.my.TotalValueOfApples +
3.50},{Scene.my.TotalValueOfApples = Scene.my.TotalValueOfApples +
5.0},{Scene.my.TotalValueOfApples = Scene.my.TotalValueOfApples +
4.50},{Scene.my.TotalValueOfApples = Scene.my.TotalValueOfApples + 6.0}];
Thomas has an apple weighing about 1dm^3, and so he puts it in his test, then Thomas puts in
an apple weighing about 4dm^3 then 3 apples weighing about 3dm^3.
Code:
Scene.my.AddAppleCost(1)();
Scene.my.AddAppleCost(4)();
Scene.my.AddAppleCost(3)();
Scene.my.AddAppleCost(3)();
Scene.my.AddAppleCost(3)();
Thomas then reads how much he would have made (keeping in mind he started with $5 worth
of apples already calculated before the previous calculation)(Scene.my.TotalValueOfApples)
and it says: $28.00.
Thyme Tutorial 15
Example:
Peter has a button, which adds one to his counter whenever he puts a banana on it.
Code:
Scene.my.NumberOfBananas = 0;
Peter eats a few bananas, and realises he doesn't like bananas, so he gets rid of his counter
link.
Code:
Keys.unbind("a",());
Thyme Tutorial 17
Example:
Sam was building a "magical" clock, he had a rough estimation of when each tick would
happen, so he used a tick based timer method to build his machine.
Code:
Scene.my.Second = 0;
Scene.my.Minute = 0;
Scene.my.Hour = 0;
Scene.my.SecondStep = 60;
Scene.my.MinuteStep = 60;
Scene.my.HourStep = 24;
Scene.my.MinuteHourTransfer = [{},{Scene.my.Minute = 0;Scene.my.Hour = Scene.my.Hour +
1;Scene.my.HourTransfer(Scene.my.Hour / Scene.my.HourStep)()}];
Example:
Thomas was noticing that his calculation for the apples could be more accurately tailored to
give him a more accurate result of how much an apple would be worth, which meant that he
would be able to sell for a more proper price, he decided to set the price at $1.50 per dm^3.
Code:
Thyme Tutorial 20
Scene.my.TotalValueOfApples = 5;
Scene.my.AddValueOfApple = (dm)=>{Scene.my.TotalValueOfApples =
Scene.my.TotalValueOfApples + (dm * 1.50)};
Thomas put in 5 apples, and his machine told him exactly how much his apples would earn
him, he put in a 3.2dm^3 apple, a 7.3dm^3 apple, a 0.2dm^3 apple, a 16dm^3 apple and a
3.5dm^3 apple.
Code:
Scene.my.AddValueOfApple(3.2);
Scene.my.AddValueOfApple(7.3);
Scene.my.AddValueOfApple(0.2);
Scene.my.AddValueOfApple(16.0);
Scene.my.AddValueOfApple(3.5);
Thomas read the machine's output and it said "$50.30", he then compared it against his old
system, and his old system read "Invalid Input" and exploded.
Thyme Tutorial 21
Example:
Damien's system is short of storage, because of his use of extremely long functions, he then
fixed it using infix operations. It was about the number of points scored
Code:
Thyme Tutorial 22
Scene.my.TotalNumberOfPointsThatWereScoredByASpecificTeamWhosnameisnottobeinclude
dforthepurposeofkeepingitopenforanyteam = 0;
Scene.my.SetPoints =
(x)=>{Scene.my.TotalNumberOfPointsThatWereScoredByASpecificTeamWhosnameisnottobein
cludedforthepurposeofkeepingitopenforanyteam =
Scene.my.TotalNumberOfPointsThatWereScoredByASpecificTeamWhosnameisnottobeinclude
dforthepurposeofkeepingitopenforanyteam + x};
Damien's new system was well within its storage limitations, Damien later planned to add
more to the code, so he upgraded his HDD.
Thyme Tutorial 23
NOTE: You must always include both true and false actions.
Example:
Tyson was working on a machine that determined whether his apples were in the "Small",
"Medium" or "Large" range, Apples in the "Small" range are within 0 - 1dm^3, Apples in the
"Medium" range are within 1dm^3 - 2dm^3, Apples in the "Large" range are above 2dm^3.
Code:
Thyme Tutorial 24
Ba. Create a box that will collide, and give it a script on one of its variables that will
run the function at all times.
Thyme Tutorial 26
Example:
John is a pineapple grower, he has a sprinkler system, he once tried using his friend's "magic"
clock, but it wasn't accurate enough to get the sprinkler system to run after 3 hours, so he built
a new system that worked with enough accuracy to get the right time to start (it was 3am
when the system was started).
Code:
Scene.my.SprinklerSystem = false;
Sim.frequency = {Scene.my.SprinklerClock;100};
Thyme Tutorial 27
NOTE: All onCollide variables can be found in the Thyme commands/variables list.
Example:
Quinn was working on a car when he realised he wanted a GPS, so he put a refreshing circle
which sent out a wave every time it hit, which gave Quinn his position.
Code:
Thyme Tutorial 28
Scene.my.Position = [0,0];
Code:
(GPSSignal)=>{Scene.my.Position = GPSSignal.pos};
Thyme Tutorial 29
For opening these files, you may need a program that can open *.zip archives like 7zip or
WinRAR.
Choice A) Rename.
1. Select the *.phz file and press F2 or open the context menu and click rename or click
on the File → Rename.
2. Select the ".phz" part of the file name.
3. Type ".zip".
4. Press Enter.
5. Press Enter or Double Click on the file.
Choice B) Open.
What is ->?
-> Is a redirection, it is used to direct you to a different structure, for example, in: Scene->{my-
>{*}}, * is in Scene.my, it can be very useful, as you can type variables like: Scene->{my-
>{Variable123 = 6;Variable456 = 2;Variable93 = 4}}, and it will come out as:
Scene.my.Variable123 = 6;Scene.my.Variable456 = 2;Scene.my.Variable93 = 4. Which can save
a lot of typing when a large amount of modifications need to be made.
Example:
Ian wanted to build a car, but found that people would always adjust his steering, he had an
automatic steering system set up, so he connected it using object pointers.
Thyme Tutorial 33
Directional control.
Code
Ian's car worked just the way he wanted it, he could now use buttons to control his car.
Thyme Tutorial 34
11. Check that you haven't made any mistakes, it should look something like
Scene.my.Value = NaN.
12. Press Enter, and the object will delete when the simulation is run.
Example:
William was walking wildly through a storm when he saw a tree had gotten in his way, he
made a machine quickly to clear the tree.
Code
William realised that his machine wasn't too effective, so he built a new machine that linked to
the main stem of the tree.
Code:
Scene.my.Machine.other.airFrictionMult = NaN;
William cleared the majority of the tree, but he linked the rest of the tree to a new machine.
Code:
Scene.my.RestOfTreeAirFrictionMult = NaN;
NOTE: These functions can still take arguments if you place the place-holders in.
NOTE: If you place a structure in the identifier, these values will be declared in the structure
that you wrote.
Thyme Tutorial 37
Example:
Vincent was looking at his flower pot and realised that it carried no information on it's type so,
he made some information and put it in the flower.
Code:
MainType := "Orchid";
SubType := "Cypripedioideae";
Genus := "Cypripedium";
Species := "Acaule";
Vincent was looking at his flower pot and realised that he couldn't see the information, so that
he could see the information, he set it all up.
Code:
text = {MainGroup := ("Main Type: " + MainType + "\n"); SubGroup := ("Sub Type: " + SubType +
"\n"); Family := ("Genus: " + Genus + "\n"); Name := ("Species: " + Species + "\n"); SciName :=
("Scientific Name: " + ScientificName + "\n");Information := (MainGroup + SubGroup + Family +
Name + SciName);Information + ""};
Thyme Tutorial 38
whatever level you like, which means that you probably wont have any trouble with
limitations.
Example:
Larry was working on a machine that would create one hundred boxes of the same type, but,
he had a problem, his system only handled about 50 deep if recursions, so Larry built a
machine that would do what he wanted by extending the for structures.
Code:
Scene.my.ForExtended = (a,r,c)=>{c < r ? {a(c)} : {};(c + 1) < r ? {a(c + 1)} : {};(c + 2) < r ? {a(c + 2)}
: {};(c + 3) < r ? {a(c + 3)} : {};(c + 4) < r ? {a(c + 4)} : {};(c + 5) < r ? {a(c + 5)} : {};(c + 6) < r ? {a(c +
6)} : {};(c + 7) < r ? {a(c + 7)} : {};(c + 8) < r ? {a(c + 8)} : {};(c + 9) < r ? {a(c + 9)} : {};(c + 10) < r ?
{Scene.my.ForExtended(a,r,(c + 10))} : {};};
Scene.my.ForExtended((number)=>{Scene.addBox{pos := [number,number];size :=
[1,1]}},100,0);
Thyme Tutorial 40
1. Go into the script menu of the object you want to build an update link for.
2. Select all of a variable you don't plan to change any time soon, like opaqueBorders or
dampingFactor or constant.
3. Type a beginning curly bracket ("{").
4. Type the name of the variable you want to update, like length or constant or motor.
5. Type an assignment operator ("=").
6. Type the value you want to set it to, like {Scene.my.lengthVariable} or 62.5 or
{Math.sin(Sim.time)}.
7. Type a semi-colon (";").
8. Type the normal value of the variable.
9. Type an ending curly bracket ("}").
10. Check you haven't made any mistakes, it should look something like {length =
{Scene.my.lengthVariable};false}.
11. Press Enter.
Example:
Arthur was building a spring controlled fork-lift, but all his length settings kept on dissapearing,
so he set up a guard system.
Code:
1. Go into the script menu of the object you want to extract data from.
2. Select all of a variable you don't plan to change any time soon, like opaqueBorders or
legacyMode or color.
3. Type a beginning curly bracket ("{").
4. Type the name of an identifier, like Scene.my.TextureMatixXYScale or Scene.my.Value
or Scene.my.XV784.
5. Type an assignment operator ("=").
6. Type the name of one of the variables linked to a widget object (like a spring menu).
7. Type a semi-colon (";").
8. Type the normal value of the variable.
9. Type an ending curly bracket ("}").
10. Check you haven't made any mistakes, it should look something like
{Scene.my.TextureMatrixXYScale = length;true}.
11. Press Enter.
Example:
Edward was building a remote control car, he had 2 sliders, one which decides whether it goes
up or down, and one which decides whether it goes forward or backward.
Code: (Spring)
Example:
Yusei was working on improving his friend's machine, his friend made a 10 deep if structure,
Malcolm's machine wasn't the most beneficial, especially because it was being executed at
100Hz
(Malcolm's Machine.)
Code:
Yusei's Machine.
Code:
(errorCode)=>{eval("Scene.my.errorCode" + errorCode)};
Thyme Tutorial 44
Code:
Example:
Nathan has a machine that has a texture, when it is hit, its texture matrix is changed.
Code:
Scene.my.MachineTextureMatrix = [0.4, 0.0, 0.5, 0.0, 0.6666667, 0.5, 0.0, 0.0, 1.0];
Code:
onCollide = (e)=>{Scene.my.MachineTextureMatrix =
(Scene.my.ElementChange(Scene.my.MachineTextureMatrix,2,9,1.0))};
Font:
http://www.algodoo.com/forum/viewtopic.php?f=13&t=411