Jump to content

Terrible Timer Troubles


8bitBiologist
 Share

You are about to reply to a thread that has been inactive for 2637 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

OK folks, I am throwing in the towel. I think it will simply take someone much better at scripting to figure this one out - if its even possible.

This is a script for the second learning game on this activity. The game is thus - there is a giant tree and to either side of it, a small factory, car, house and stump. Above it is the earth, rotating, with a shimmering red arura around it. The game is about global warming. The tree shrinks over time and as it shrink, the red aura around the earth becomes more opaque representing global warming.

GameDraft1_001.png

Now, the mechanics of the thing - The player can click on the tree, effectively "planting" a tree and reducing the amount of CO2 in the atmopshere. So in the script there is a simple counter and set text. Whenever the tree is clicked, it subtracts one from the counter. The text (millions of tons of CO2) goes down by one. AFTER 1 second from game start (llMinEventDelay?) there is a llSay that informs the player that the Industrial Revolution has begun. In turn, this begins a timer event that automatically adds 1 to the counter as more CO2 is added to the atmosphere. After 10 seconds, , there is a Say that says that now cars are invented, and the SetTimer becomes +2 per second instead (since it supercedes the last one), and I have other such events until the 500 becomes 1000 at which time the game is over.

 

The prims of the factory and houses etc are llListening for the llSay and will get bigger when they hear that.

The tree itself will change scale based on the inverse of the CO2 - so the more CO2, the smaller the tree gets. Maybe llSetScale(<500/count,1.0,500/count>); ?

 

The opacity of the red aura will change with a llSay after the update() that looks for if ( counter > 600) say something like "It's Getting Hot". THe red aura is Listening and will change to maybe 0.5 Alpha and so on.

I would make this separate scripts in the object but they all run off of that one integer count and I don't know how to carry that constant to other scripts since it is constantly changing by the clicking. Anyways, here is the little that I have;

// Doc: count the current touches

integer count = 500;

update() {
llSetText("Millions of Metric Tons of CO2 in atmosphere = "+(string) count, <1,1,1>, 1.0);
}

default
{
on_rez(integer p) {
llResetScript();
}
touch_start(integer p) {
count = count-p;
update();
}

state_entry() {
update();
llMinEventDelay(5.0);
llWhisper(0,"The Industrial Revolution");
llSetTimerEvent(1.0);
}
timer()
{
count = count+1;
update();
}

}

 

This is what I have been playing with but it's not working and I don't think I am making any progress. Any insights or maybe similiar scripts that I could use to help me would be appreciated.

Link to comment
Share on other sites

I'll repeat my earlier suggestion that you spend some time working through LSL tutorials or taking a free class at someplace like Builder's Brewery before you go much farther.  You're still making the same basic syntax errors that showed up in the first script you posted. For example,

touch_start(integer p) {    count = count-p;    update();}

will go nowhere. The variable p records the number of avatars that are detected as the touch_start event is triggered.  It's limited use is in distinguishing between the responses of two or more people who click your object simultaneously. That's not what you want to do here.  If you want to reduce the value of count by one each time you enter touch_start, write

count = count -1;

or, better,

--count;

A little time spent on learning the language will go a long way toward easing your frustration.  For another example, you will learn quickly that there are many good ways to pass information from one script to another.  You have llSay, llWhisper, llShout, llRegionSay, llRegionSayTo, and llMessageLinked to work with, for a start.  Once you get to working at it, you'll find that you often don't need to communicate between scripts at all, but can run everything from one single script.

Syntax aside, though, scripting is about applied logic. To write a working script, you need a very clear roadmap so that you know precisely what the script will need to do (and not do).  Until you can carry a lot of that in your head without being distracted by unfamiliar syntax, it's smart to get out pencil and paper and make an old-fashioned flow chart. Map out exactly what tasks you need to accomplish and what actions and decisions you will need to make along the way until it is clear enough that your 10-year-old or your grandmother could understand it.  Then start writing, one little sub-task at a time.

BTW, when you post a script here, the Spoiler option certainly works but your scripts will be more readable if you use the little code widget that you access by clicking the C symbol right above your editing window.  Especially in longer scripts, too, it will be much easier to read your scripts if you follow standard conventions for indenting each nested scope in your script.

  • Like 1
Link to comment
Share on other sites

Actually that one I corrected in one iteration - yeah I copy the scripts, then modify them. That bit I did catch earlier but apparently had not fixed in this draft.

 

I wish I had that time  =)  to take classes. In 2 weeks from today I will have some 40 students taking my Biology classes, and these activities are part of their curriculum. This one is just one of many. Luckily most of the others are not as complex but I do wish I had the time to be both a teacher and a programmer. It's either winging it and using the help of folks in the community or the kids this fall get pen and paper. Who wants that?? So any help will be appreciated.

I didn't see the code widget. I will use it from now on!  And I do know exactly what I want the script to do, as outlined, but..just don't know how to get it there. I'll bench this activity and work on others until someone can pipe in with a good solution. Still have about a dozen or so activities to sctript ^.^

Link to comment
Share on other sites

  • 2 weeks later...


8bitBiologist wrote:

the kids this fall get pen and paper. Who wants that??

the kids most likely

with pen and paper they can also learn how to create flowcharts and logic diagrams pretty easy. Kids also like crayons and paint. They can draw and colour in their own trees and cars as well

not everything kids learn must have a computer to do

altho if you have sold the needs computer idea/concept as a must have to the school faculty then can see how that might be a problem if do eventual turn up with pen and paper and crayons and paint. which I suppose answers your question of who wants what

Link to comment
Share on other sites


8bitBiologist wrote:...

or the kids this fall get pen and paper. Who wants that?? So any help will be appreciated.

I agree, pens and paper are great!  The number of times i've dropped a pen, or a pad of paper, stood on it, bent it and thrown it across the room and it still works is numerous.

Plus, few pens or pads of paper need electricity to run unlike the computer being used to demonstrate the effects of energy use and global warming.  A tad bit of irony there ;)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2637 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...