CS 199: SPST Games ~~~~~~~~~~~~~~~~~~ Advanced programming assignment This is the "advanced" programming assignment. It is intended to for the students in the class with previous programming experience. By doing this assignment, you will be exempt from having to hand in assignments 9 and on. (You will still need to do a final project) If you have programming experience, doing this assignment will be much more rewarding and educational. If you know what a variable is, what a function is, how to write for and while loops, how to structure if/elseif conditionals, this is probably the assignment for you. There are three tasks. You only need to do any two of them. This assignment is due when you hand in your project proposal. I will not be lecturing on how to solve any of these problems in class. LSL is really easy to pick up if you have previous programming experience, and I am more than happy to discuss the problems/solutions with you. Task #1: ~~~~~~~ - On PSU CS199 island, you can get a free copy of a "Simplified Dice". - Your task is to construct a system where you can hit one button, and it will automatically roll 6 dice, each a different colour. You will then have a system of displaying the results as an llSetText() (floating letters above the prim) in sorted order, as well as the total. Task #2: ~~~~~~~ - On PSU CS199 island, you can get a free copy of a "FIC Detector". - What this object does is to scan the nearby area for avatars, and figure out their age in days. It displays the number of avatars, the average age, and cycles through all the detected avatars, displaying their age. - As an additional constraint, you must design your program with two scripts - one which is responsible for sensing nearby avatars, and the other for displaying information. They should communicate using llMessageLinked(). - Hint: http://forums.secondlife.com/showthread.php?t=36315 This thread in forums provides code that converts a date into a number. Task #3: ~~~~~~~ - Choose any classic computer science problem, and implement a solution visually represented in Second Life. - Example problems: Towers of Hanoi, Conway's Game of Life, Travelling Salesman, pathfinding algorithms, sorting algorithms (mergesort, quicksort, bubblesort, etc) - As an example, I've rezzed a copy of a self-solving Towers of Hanoi on PSU CS199 island. ------------------------------------------- The following is a basic primer on teaching yourself scripting in Second Life: Things to know: - The default linden documentation is garbage. Don't use it. - Resources: The best resources for scripting documentation in SL: http://www.lslwiki.net/ Scripting tips forum: Best place for Q&A on scripting: http://forums.secondlife.com/forumdisplay.php?f=54 The scripting library: Many free scripts to examine to look at http://forums.secondlife.com/forumdisplay.php?f=15 About LSL: - LSL is a C/Java-like language. The syntax is very similar. - The only data types are: integer, float, vector, rotation, key, string, list *Note: There are no character or unsigned data types. - LSL does *not* have boolean shortcutting. So expressions like if ( function1(value) && function2(value) ) will evaluate function1(value) and function2(value), regardless of what function1(value) returns. - LSL is *always* by value. There are no references or pointers. - There are no arrays in LSL. The closest thing you get are lists. - Each script is limited to 16KB of memory. - All built-in LSL functions are preceeded by "ll". eg. llSay() - llSay(), llInstantMessage() are ways to communicate text to people - llOwnerSay() is a useful tool for debugging - LSL is an event driven language. For example: default { state_entry() { llSay(0, "Hello, Avatar!"); } touch_start(integer total_number) { llSay(0, "Touched."); } } In this example, state_entry() is the default event - this event is triggered when you script starts to run. touch_start() is the event that triggers whenever someone touches the object that this script is in. In this case, whenever anyone touches the object, it will chat, "Touched". - Scripts can react to chat message - look into the llListen() function and the listen() event for details. - Multiple scripts inside the same object can communicate with link messages. Look into llMessageLinked() and the link_message() event. On Rotations (advanced subject): - Rotations in LSL are represented by the "rotation" data type, which is a quaternion. - It is not generally helpful to understand what a quaternion is. - You can convert between euler coordinates and quaternions using llRot2Euler() and llEuler2Rot(). (Be aware that Euler coordinates in LSL are expressed in radians, not degrees) - The important properties are: - You can transform a vector with them v*r = v' - You can compose rotations together r1 * r2 = r3 - Rotations are all invertible, and associative, but not commutative 1/r, (r1*r2)*r3 = r1*(r2*r3), r1*r2 != r2*r1 - You can use all these ll* functions to manipulate them. http://www.lslwiki.net/lslwiki/wakka.php?wakka=rotation