Affichage des articles dont le libellé est scripting. Afficher tous les articles
Affichage des articles dont le libellé est scripting. Afficher tous les articles

mercredi 29 août 2007

Linden Logic

or: 1=1 is NOT TRUE!

Scripting a bit 5 came across some strange characteristics of the scripting language of Linden Lab. Strange characteristics mean that it wont do what you expect, or that you have to be very careful working with it. Programming is following intuitively rules about how the language in general functions. Intuition stumbles over these strange things, they are not expected. Bugs come in various sorts and kinds, the stupidities, the typing errors, the designs which are simple not working, but the most awful to debug are the results of situations where the script is plainly not well designed.
In principle you can program everything because of Leibnitz’s great phrase: Nihil est sine causa, or nothing happens/is without a reason. It was of course Heidegger who turned this around in: Being is just that which has a reason. So since programming is just following the lines of causing, you can program everything which is. Only some things take a bit more time to program than others. This more time is multiplied by 2 because of illogical features of a language.
An example, a string is a sequence of characters or numbers or spaces. You can print a string. For instance a name is a string. Inserted in a string can also be a command like new line. Then you can add to your name a telephone number, or an email address. The address can be on the next line. So far the Lindenscript is ok. Then the script offers the floating text llSetText. In it you can put a string and it will be displayed above the prim it is in. And suddenly the string behaves differently! Two commando’s new line placed directly behind each other will give only one new line. The same string in the llSay commando displays the two new lines without a problem. So putting a string like that in a floating text, you have to search for two RETURN’s and put a space between them…….(my oh my…)
Then you decide that the string has to be placed in a database and want to retrieve it again. For this llEscapeURL is used, because of the niceties of the HTML posting, putting %20 where there is a space. That’s is ok so far, but then you actually want to retrieve a large string, so you go the other way around: llUnescapeURL, and behold: the string is shortened considerable! What has happenend, oh dear, search the dBase, search your script, pull you’re hair out!!!
But no: Lindenscript, thank you: this function llUnescapeURL only returns a string with 254 characters, so it cuts off a string which is as a string is defined, in principle without a limit, the limit being the memory available. SO strings can be as long as you want, but using llUnescapeURL it is cut off, and also this cutting of gives a PARSE error in the client…..hmmm, we like that very much, mister Linden!

Talking about the database, you can make a lot of things possible working with a database. The Lindenworld is slow, but get your data to a PHP page connected to a database, you can get the speed of a PHP page connected to the trigger from SL. In ideal combinations for making games possible which need lots of calculations.
Here again something strange happens. The answer coming from the dBase is a string (yes!!! there we go again….) in front of this string is a mysterious return, which is not traceable, nor can be filtered out. That means that if the answer from the PHP page is 1, you cannot compare it to the number 1, nor with the string 1, because this one has the mystery RETURN in front and so is different!
So 1==1 can be FALSE!!!
Now, to get around this 5 uses this trick: let the PHP page send this back: 0 *** 1, then make this a list, with llParseString2List, so it becomes [0,1], the first 0 being contaminated, and just take the second entry in de list!!! This way you avoid the contamination, and 1==1 is TRUE again, as it should be.
This all is clumsy, and has cost a lot of debugging time. Being is that which has a reason. But it doesn’t have to be reasonable it seems, in de SL scripting world.


dimanche 27 mai 2007

Five in a tent, TP, tipi

Hello Five, do you see this teepee, Amiryu said. Which tp? (Which tp is normally short for teleportation.) “And how can I ever see a tp?”, Five thought, seeing a teleportation is like seeing a thought, or a sentiment, a teleportation carries a name, but it is not a tangible object, not even in Second Life. But no, a teepee is a tipi, an Indian tent! Funny, the words tp and teepee having the same sound, even in chat. It is easy to get confused. Well Amiryu showed the teepee to get some work done: the teepee has to belong to a tribe, and each tribe has different decorative signs on their teepees and these tribes, being very sophisticated, change their symbols by a very smart dialog box appearing at the upper right corner of the screen of their laptop. But this nice blue dialog box, a sort of a menu has to be programmed. That is where Five March (who, by the way, is borne on the 6th of January) comes in. All sides of the tent, depending on which tribe, have to change in a given pattern, and the entrance has to be opened and closed. A nice fire must be around, and a powerful drum, which sounds makes all the tents in the neighborhood belong to the same tribe. Yes, even in Stone Age societies the laptop has been introduced, disguised as a drum. May be these societies even had their laptop before the cowboys, who knows what was hidden under the beautiful hides?
Well, an hour of programming Five thought, hmmm. This Five never learns anything. Five is always underestimating the amount of work. At the end it was a full morning, because Five wanted to program smart and because of all kinds of stupidities. Trying to be smart often leads to foolishness. In programming it is the stupidities which cost time. And in Second Life the transfer of the object worked on also costs time, because of the setting of the permissions.

Two examples of what can go wrong. To have a quick laugh! First all the textures were loaded in the sides and the part of the menu visible on the screen of the inventory of these objects were completely filled. In one side of the tent one of the textures, all with permissions copy and modify was accidentally introduced twice. What happens? Second Life doesn’t accept the same names in the inventory of an object so puts a “ 1” behind the second name. And at the same time sets the permissions as it normally does: no copy no modify! Logically, but when assembled, it takes an hour to find out where it goes wrong.
Second mistake: all the scripts where painstakingly set to copy. But in some inventory menu of some object of the tent another script was created. It disappeared under down under in the menu, which, because of the many textures, wasn’t visible anymore. New scripts: of course, no modify, no copy. This script, doing nothing, quite empty, also caused a headache, because it was invisibly hidden outside the screen border in a menu which was longer then the screen could show. And because all the other sides were ok…..
Some lessons to be learned here: be more careful Five, don’t mess around!
After a lot of transferring all resulting in “no modify”, the tent was transferred piece by piece, until the side causing all the pains showed up, and betrayed it evil intentions of not wanting to be modified by Amiryu. Then everything was quickly assembled. Only Amiryu had figured out a better name for a tribe! Never change names in software, after everything is assembled. If not prepared for name changes, these names can be everywhere….and they were everywhere. The teepee had to be disassembled again, all the scripts changed, reassembled again. All these simple tasks, after the writing of a really smart piece of software were killing Five. Five wanted to jump out of the window. But in Second Life, being perfectly able to fly, you only fall a bit on the ground, doing a falling animation, in this case in the desert, so happily no harm was done. The teepee was finished at last. Even the fire was an innovation. Using the time difference between touch_start and touch_end, you can make smoke signals!
Ok Five had learned another lesson. Actually quite a few. Some new ideas were developed too. All is well that ends well!
The teepees, or tipis, or tents can be found in Virgin Island in the desert. The tents are hidden in a no go area, so beware, don’t go there!

mercredi 23 mai 2007

Five thinks linked

Five likes to think about life, first or second. At the same times Five programmes a lot. This is called scripting in Second Life. So Second Life two lines of interests come together, the reflections and the programming. Sometimes these are mingled: Five looks at life from a gaming point of view: if we change this or that setting in life, what would happen? Most of the time, if you think well, you cannot escape the conclusion that life is a very good game. This is the position of poor old Leibniz: this is the best of all worlds! At the same time you see that so much is so wrong! It was not difficult for Voltaire to ridicule this observation of Leibniz, for instance in his novel Candide.
There we go again, you might think, but no, this time Five stays practical.
Five wants to show you something. A handler which might be handy when working with linked objects. A linked object, when scripted, mainly functions from its root object, sending messages to the links, or receiving info from these links. The linked objects have numbers, depending on which order you follow linking them together.
If you change the order, the numbers are changed. This is terrible! For instance making a HUD with digits, you have to be careful to take the same order, and when you decide to link something within this order, you can change the whole script! This is because although the function llGetLinkName(integer linknum) exists, there is only llGetLinkNumber() in the link itself! Not something like llName2LinkNumber(string name)!
And this is quite needed, sending commands to the links from the root, with
llMessageLinked().
So Five proposes a small function, see how it works:

This is all taking place in your root script, please give a name to every link, for instance (for the digital clock) digit1, digit2, digit3, digit4, digit5, digit6, etcetera.
Than at the top of your script you declare a list, linkNameList. Then you make a function, going through the whole list of linked objects, and noting the names of the objects. It is as simple as that.


list linkNameList = [ ];
///////////////////////////////////////////////////////////////////////
//getting linknumbers from link names this in state_entry handler
getLinkNameNumberList()
{
integer x;

//x=0 is taken by the root returns 00000000-0000-0000-0000-000000000000
//so we have to go to llGetNumberOfPrims() + 1, to get all the linked objects

for (x=0;x<llGetNumberOfPrims() + 1;x++)
linkNameList +=[x,llGetLinkName(x)];

//these last lines can even be left out, just for checking
integer check = 0;//if check = 1 this gives list of numbers and names
if (check==1)
for (x=0;x<llGetListLength(linkNameList);x+=2)
llSay(0, (string)(x / 2) + " " + llList2String(linkNameList,x) + " " + llList2String(linkNameList,x+1));
}

Ok, then all we need is a small function to be used in the rest of the script, simply replacing the name of the object by the number. Put this function also above the default

// linkName -> linkNumber
integer name2LNum(string linkName)
{
integer x;
for (x=0;x<llGetListLength(linkNameList);x+=2)

if ( linkName == llList2String(linkNameList,x+1) ) return x / 2; //the 2 is because of the ‘strided’ list
return 0; //returning 0 means an error: name not found
}

At the state_entry of the default, we simply call the preparation….

default
{
state_entry()
{
getLinkNameNumberList();//this prepares the list of names and linknumber
//etc….

And now somewhere else in the script, instead of

llMessageLinked( 12 , my1000, "", NULL_KEY); //where 12 is the number of the link

and you can edit and renumber the 12 every time the link order is changed, you use the nice function, just by the putting in the name of the linked object you want to send a message
llMessageLinked( name2LNum("digit4") , days, "", NULL_KEY);
llMessageLinked( name2LNum("digit3") , hours , "", NULL_KEY);
llMessageLinked( name2LNum("digit2") , minutes , "", NULL_KEY);
llMessageLinked( name2LNum("digit1") , seconds, "", NULL_KEY);

So regardless of the linkorder or the complexity of the linked prim, the script will find your digit without a problem!