Mitzpatrick Fitzsimmons
Neurotican Mage
Join date: 20 Sep 2004
Posts: 62
|
08-07-2005 11:09
Greetings,
I have been having a little problem trying to figure out lists, errr... well more like having the list I want to be dynamic to hold specific information and update the list when certian conditions apply.
What I want is this:
>A list that holds 2 integers [200, 200] for example.
>A function that will update the list with New Information that will be passed via Chat on channel 1...but it needs to add the new info to what is currently in the list:
Example: If the list Currently holds [200, 200], and the New Info passed via Chat is /1 "34" "55" (without quotes) then the list will now hold [234, 255]. ..not [200, 200, 34, 55] (which is what I have been getting).
>Another function similar to the one above that will update the list by SUBTRACTING the New Information passed on Channel 2 from what is currently in the list.
Example: If the list is [200,200] and the New Info on Channel 2 is /2 "34 "55" (without the quotes) then the list will now be [166, 145]
>A function that will llOwnerSay the current info in the list when it hears /1 say list
I also would like a function that will reset the list to [0,0] with the command: /1 reset; (and in the on_rez event)
The variables in the list should always be integers.
I do not have lost of Lindens to donate to the person that can generate this code for me, but I will be using it for a game I am making, and will definately give you notable credit for helping me.
Thanks,
-Mitz
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
08-07-2005 12:07
The thing to keep in mind is: a list is not a variable or a collection of variables, it's a collection of static data. list data = [200,200]; list delta = []; list add(list target, list add) // Be sure they're both the same length. { integer i; integer l = llGetListLength(target); list output = []; for (i=0; i<l; i++) { output += ( llList2Integer(target, i) + llList2Integer(add, i) ); } return output; } list sub(list target, list sub) // Be sure they're both the same length. { integer i; integer l = llGetListLength(target); list output = []; for (i=0; i<l; i++) { output += ( llList2Integer(target, i) - llList2Integer(sub, i) ); } return output; } state default { state_entry() { llListen(1, "", NULL_KEY, ""); // Addition and command chan llListen(2, "", NULL_KEY, "");// Subtraction chan } listen(integer chan, string name, key id, string msg) { if ( msg == "reset" && chan == 1 ) // if reset and channel one { if ( id == llGetOwner() ) data = [0,0]; // AND it's the owner, reset the list } else if ( msg == "say list" && chan == 1 ) // if say list and channel one { if ( id == llGetOwner() ) llOwnerSay(llDumpList2String(data, ", ")); // AND it's the owner, report the list } else // otherwise assume it's a numbers list { delta = llParseString2List(msg, [" "], []); // parse the string into a list if (chan == 1) // if it was sent on chan 1, add { data = add(data, delta); } else if (chan == 2) // if on chan 2, subtract { data = sub(data, delta); } } } } Not compiled in-world, but it should work as the example it was intended to be. 
|
Mitzpatrick Fitzsimmons
Neurotican Mage
Join date: 20 Sep 2004
Posts: 62
|
Hmmm
08-07-2005 13:05
THanks for the speedy Response, but it doesnt seem to complie...
I updated the script to compile (forgot a } to close state) but then it said error in the sub list function here (in the for statement):
add += ( llList2Integer(target, i) - llList2Integer(sub, i) );
so I changed it to:
sub += ( llList2Integer(target, i) - llList2Integer(sub, i) );
Then it compiled...but
Now it doesn't add values or subtract values when sent on the respective channels...it just comes up empty...
/1 reset works fine to reset values to [0,0] though...
Any ideas?
-Mitz
_____________________
 I dont know it all...just enough to be "Dangerous!"
|
Minsk Oud
Registered User
Join date: 12 Jul 2005
Posts: 85
|
08-07-2005 13:41
Where the code has "add +=", it should have "output +=". I think that is the only remaining problem...
_____________________
Ignorance is fleeting, but stupidity is forever. Ego, similar.
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
08-07-2005 14:30
Yep, made the changes. Still haven't tried making it compile.
|
Mitzpatrick Fitzsimmons
Neurotican Mage
Join date: 20 Sep 2004
Posts: 62
|
That Works!
08-07-2005 16:24
THank you both (again) SOOOOO MUCH!
-Mitz
_____________________
 I dont know it all...just enough to be "Dangerous!"
|