CS 199: SPST Games ~~~~~~~~~~~~~~~~~~ Assignment 9: ~~~~~~~~~~~~~ - Examples of all these tasks are available on "PSU CS199" Task 1: ~~~~~~~ - Create an object that prints 1 to 30 when you touch it Task 2: ~~~~~~~ - Correct the following script // This program describes what it is trying to do in the comments. // However, everything it *actually* does is wrong. Fix all the // things that are wrong. default { state_entry() { } touch_start(integer total_number) { integer foo; integer bar; integer var; // 1) Set foo to 3 and bar to 2 foo = 12; bar += 52; llSay( 0, "1) foo = " +(string)foo + " bar = " + (string)bar ); // 2) Sum foo and bar together, and store the result in "var" var = foo + foo + var; llSay( 0, "2) var = " +(string)foo + " + " + (string)bar + " = " + (string)var ); // 3) Multiply foo by 10 foo = foo + 18; llSay( 0, "3) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); // 4) recalculate var as the sum of foo and bar foo = foo + bar; llSay( 0, "4) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); // 5) Add 1 to foo, bar, and var. foo--; bar += 5; var = foo + 1; llSay( 0, "5) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); } } Task 3: ~~~~~~~ - Create an object that calculates the sum of all the numbers from 1 to 100 when you touch it. Your program must actually calculate this number. llSay( 0, "The sum of 1 to 100 is: 5050") is *not* a valid solution Task 4: ~~~~~~~ - Take the following program, and replace "......" with descriptions of what the program is doing in english // - Take the following program, and replace "......" with descriptions of what // the program is doing in english default { state_entry() { llSetText( llGetObjectName(), <1,1,1>, 1 ); } touch_start(integer total_number) { llSetText( llGetObjectName(), <1,1,1>, 1 ); integer foo; integer bar; integer var; // 1) ...... foo = 4; bar = 5; var = 6; llSay( 0, "1) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); // 2) ...... var = foo * bar; llSay( 0, "2) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); // 3) ...... var = var / bar; llSay( 0, "3) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); // 4) ...... var = foo + foo + foo; llSay( 0, "4) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); // 5) ...... bar += foo; var += bar; llSay( 0, "5) foo = " +(string)foo + " bar = " + (string)bar + " var = " + (string)var); } changed( integer code ) { llSetText( llGetObjectName(), <1,1,1>, 1 ); } }