Pages: 1
Topic closed
Say there's a list of only 3 numbers: 2, 4, 8.
How do I write a script to add them up??
And, if numbers keep being added to the list, one by one, how do I keep a running total??
(Why haven't I been able to do this so far??)
Offline
Try this script
set sum to 0
set i to 0
repeat (length of list){
change i by 1
change sum by (item (i) of list)
}
Offline
Thanks, archmage!
It works perfectly.
I had all the right components but I just couldn't think it through correctly. And in each case I could see why I was getting the wrong result (the script, unfortunately, was doing *exactly* what I told it to do), but I never could work out the logic.
Thanks again!!
And it's truly an honor to have one's problem solved by one of the most famous Scratchers of all!!
Offline
Nah, I am not that great. I learned how to do this sort of stuff in java class.
Heres a tip, its easy to go though things using an i variable.
For example
//check if touching an enemy //Enemies are labled enemy1 to enemy10 set enemies to 10 set i to 0 repeat (enemies){ change i by 1 if touching (join (enemy)(i)){ say(oh no!) } }
Don't feel bad abut not working out of logic. For a lot of things in programming you have to learn it from a source because it is too complex to just make up.
Last edited by archmage (2010-02-27 13:10:29)
Offline
Topic closed
Pages: 1