Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

100 pigeon holes! ?

Sharon Ewry
Registered User
Join date: 30 Nov 2006
Posts: 33
04-02-2007 22:49
Hello!

I have a little problem and as even though i checked the scripting guides still have no idea how to write this one.

I know it wouldn't be to hard as i can write it in basic ( thats prob my problem,, still have that language in my head )
ohh i loved the days with line numbers.. this would of been so easy... 10 dim names(100)

anyway

i want an object to remember the last 100 people that clicked it for a notecard, but only adding there name to the list if they haven't clicked it before.

I can make it give the notecard no problem and everything..

Its how you set the object save 100'places for names and how you add the new entries if they haven't clicked it before that i can't work out.

If i got this part out of the way, the rest will be easy enough and i won't have to keep throwing tantrums at my pc hehe

So if any of you know how or can give me any idea's, i would be most grateful !

thanks again guys

Shaz x
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
04-02-2007 23:02
http://lslwiki.net/lslwiki/wakka.php?wakka=llListFindList

using a list may be pushing memory limits, and in the higher numbers it will be slow, i do something simmilar with php

example flat file guest book thing
CODE

<?php
$filename = "userlog.dta";
$search = $_GET["search"];
$user_data = file($filename);

for($x = 0; $x < count($user_data); $x++)
{
$user_data[$x] = trim($user_data[$x]);
}
$search = trim($search);
$on_list = array_search($search,$user_data);

if ($on_list !== FALSE)
{
echo "on list";
}

else
{
$fp = fopen($filename,"a+");

if(!$fp)
{
echo "Error: Cannot open file.";
exit;
}

fwrite($fp,$search."\n");
fclose($fp);
echo "new user added";
}
?>
Sharon Ewry
Registered User
Join date: 30 Nov 2006
Posts: 33
04-02-2007 23:18
Its only going to need to hold 100 names and the rest of the script is easy, it will just give out a notecard so should be well within memory limits, if it was to struggle with 100 though i could reduce it to 50 at a push.

That code you placed, i don't really know how to change it to use it in SL, i am still a new to scripting and although learned a fair bit this part is still new to me :)

I know i could just set 100 strings, 1 for each name then check each string when trying to add a name and then if not already added moving each name down one to add a new one but that would make the script huge and i would rather know the proper way of writing it.. just struggling grrrr

Thanks

Shaz x
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
04-02-2007 23:32
you would stick that on a webserver and use http request / response to move the data back and fourth, back to lsl and list tho


best way to see if its acceptable is to load a list with some dummy data (ie texure names) and have it find an entry

it should hold 100 names with little issue but it will start taking noticable amounts of time once in the dubble digits ... the more the slower, but its really a game of how long can you stand to wait vs script speed
Sharon Ewry
Registered User
Join date: 30 Nov 2006
Posts: 33
04-02-2007 23:39
Now your just going way over my head... lol

Its just in the prim i want to store the names even if it meens reducing the size of list :(

Shaz x
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-02-2007 23:45
The code isnt that complex.
You just need to maintain a list and check its size each time it grows and prune the first element if it exceeds you required size.
CODE

string Notecard = "Your notecard name here";
integer Max = 100;

list Names;


AddName(string name)
{
// Add the new name. 'Weird' Syntax is a known LSL hack to save memory
Names = (Names = []) + Names + [ name ];

// Prune time ?
integer size = llGetListLength(Names);
if(size >= Max)
{
// Delete the first entry (oldest)
Names= llDeleteSubList(Names, 0, 0);
}
llSetText((string)size + " / " + (string)Max,<1.,1.,1.>,1.);
}

default
{
state_entry()
{
llOwnerSay("Running. " + (string)Max + " Names allowed in list.");
llSetText("0 / " + (string)Max,<1.,1.,1.>,1.);
}

touch_start(integer total_number)
{
// Find who touched us
key id = llDetectedKey(0);
string name = llKey2Name(id);
// Are they in the list ?
integer index = llListFindList( Names , [ name ] );
if(-1 == index)
{
AddName(name);
llGiveInventory(id, Notecard );
}
else
{
llSay(0,"You already have a notecard!");
}
}
}


obviously it would be nice to have some functionality to allow the owner to get the data held in the list but you didn't ask for that ..... :)
Sharon Ewry
Registered User
Join date: 30 Nov 2006
Posts: 33
04-03-2007 00:03
From: Newgate Ludd
The code isnt that complex.
You just need to maintain a list and check its size each time it grows and prune the first element if it exceeds you required size.
CODE

string Notecard = "Your notecard name here";
integer Max = 100;

list Names;


AddName(string name)
{
// Add the new name. 'Weird' Syntax is a known LSL hack to save memory
Names = (Names = []) + Names + [ name ];

// Prune time ?
integer size = llGetListLength(Names);
if(size >= Max)
{
// Delete the first entry (oldest)
Names= llDeleteSubList(Names, 0, 0);
}
llSetText((string)size + " / " + (string)Max,<1.,1.,1.>,1.);
}

default
{
state_entry()
{
llOwnerSay("Running. " + (string)Max + " Names allowed in list.");
llSetText("0 / " + (string)Max,<1.,1.,1.>,1.);
}

touch_start(integer total_number)
{
// Find who touched us
key id = llDetectedKey(0);
string name = llKey2Name(id);
// Are they in the list ?
integer index = llListFindList( Names , [ name ] );
if(-1 == index)
{
AddName(name);
llGiveInventory(id, Notecard );
}
else
{
llSay(0,"You already have a notecard!");
}
}
}


obviously it would be nice to have some functionality to allow the owner to get the data held in the list but you didn't ask for that ..... :)


hehe thanks loads for that, i have so much to learn yet!

the getting list of names part i should be able to work out,, would rather it be that way though as then i will learn to understand what you have written better.

Thanks loads and loads for that, very much appreciated.

Shaz xx
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-03-2007 00:28
From: Sharon Ewry
hehe thanks loads for that, i have so much to learn yet!

the getting list of names part i should be able to work out,, would rather it be that way though as then i will learn to understand what you have written better.

Thanks loads and loads for that, very much appreciated.

Shaz xx


I wont write it for you then :) but heres a hint, you already have the list, Names, you just need to iterate through it when requested.
Tegg Bode
FrootLoop Roo Overlord
Join date: 12 Jan 2007
Posts: 5,707
04-03-2007 03:00
Hey does this remember the data it is stored in inventory, looking for a way to store around 30 numbers in a HUD that are changeable but remembered no matter what happens.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-03-2007 03:39
From: Tegg Bode
Hey does this remember the data it is stored in inventory, looking for a way to store around 30 numbers in a HUD that are changeable but remembered no matter what happens.



A script's variables SHOULD retain their values unless explicitly reset either by the user, llResetScript() or by some problem with the dataserver/SIM
Tegg Bode
FrootLoop Roo Overlord
Join date: 12 Jan 2007
Posts: 5,707
04-03-2007 04:10
From: Newgate Ludd
A script's variables SHOULD retain their values unless explicitly reset either by the user, llResetScript() or by some problem with the dataserver/SIM


Cool,thanks so removing the HUD or lioging out shouldn't clear it, but if that data is basically iriplacibale like a gambling chip balance, is there a better way or should I just have the data backed up regualarly to a server prim elsewhere.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-03-2007 04:34
From: Tegg Bode
Cool,thanks so removing the HUD or lioging out shouldn't clear it, but if that data is basically iriplacibale like a gambling chip balance, is there a better way or should I just have the data backed up regualarly to a server prim elsewhere.


If its "game" (i.e. an in world game) related data then from a security / integrity point of view it should never be stored anywhere apart from on the game servers. Storing it in a local prim/HUD would mean loss of data if they are damaged/reset. That said in world servers suffer from the same limitations. Periodic dumping of data to a notecard or 'hard' storage via prim parameters (for very small amounts of data) is a better solution but for real integrity off world is required.
Brain Curry
Registered User
Join date: 15 Jun 2006
Posts: 9
04-03-2007 19:57
From: Newgate Ludd
If its "game" (i.e. an in world game) related data then from a security / integrity point of view it should never be stored anywhere apart from on the game servers. Storing it in a local prim/HUD would mean loss of data if they are damaged/reset. That said in world servers suffer from the same limitations. Periodic dumping of data to a notecard or 'hard' storage via prim parameters (for very small amounts of data) is a better solution but for real integrity off world is required.


You can't automatically create notecards, or any other kind of unbounded storage (or near-as-dammit) in-game.

The only solutions to this revolve around LSL's ability to talk to external servers, which you will have to maintain yourself or pay someone to. You can go via email, standard http, and xml-rpc, which is really exactly like http but more annoying and less scalable. Not that scalability matters for this world, but it is annoying.

Well, I'm annoyed by it, at least.

Back to the point, if you have an email address or a web server, you can maintain as large a database as you want. Collate names/UUIDs into a list and when you hit some magic threshold email it somewhere. If you're feeling really frisky you could attach it to a roving bot using llSensorRepeat() collecting avatar UUIDs which feed to a web server. Said web server also doles out chunks of known UUIDs to spam bots which IM the prospective buyer every three or four seconds about your amazing new offer.

The possibilities are really endless. Enjoy your free accounts!
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-03-2007 23:50
From: Brain Curry
You can't automatically create notecards, or any other kind of unbounded storage (or near-as-dammit) in-game.


Sorry I never intended to imply that you could. When I said dump to notecard I meant as a manual backup.

Memory prims, a number of scripts running purely to handle data storage, do work reasoanbly well for small-medium amounts of data, but yes, as I originally stated, off world is the only real way to handle large quantities of (semi-)persistent data.