Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

list type return problem?

Epiphany Absolute
Registered User
Join date: 19 Jun 2005
Posts: 19
07-17-2005 13:36
I'm writing a script that has a function that creates a list from data generated in a function, which then returns that list. For some reason, the list should be valid before it is returned, but when I access the list with any llList2* function, it returns a blank list element.

Here's an example:

list generate_list()
{
list dealt;
dealt = [(integer)suit, llList2Integer(diamonds, (integer)card)];
return dealt;
}

and touch_start:
touch_start(integer total_number)
{
list card;
card = deal();
llSay(0, (string)llList2Integer(card, 1));
}
no matter what I try, it always outputs 0, in the function or in touch_start...any idea why this is so? Also, doing a while that runs while the 1 position == 0 never stops running. It's as if the data isn't being set...even though it is.
cell Neutra
That's L$50k please
Join date: 26 Sep 2004
Posts: 28
07-17-2005 15:46
Hi there.

Unless you are assigning a suit after you retrieve the card, which I doubt, then the value card will be a list comtaining both the value and the suit. and i take it your suit is the first element of your list card and the value would be the second. I suspect the error may be in your value naming. If you are using J,Q,K,A values, the llList2Integer will always return a 0. You can actually use this to your advantage by changing A to 1, and leaving J,Q, and K. You then use

integer value = llList2Integer(card,1);
if (value == 0)
value = 10;

Hope this helps, and, as someone who has programmed several card games, I hope you are ready for more of these problems :P

cell Neutra
Rayve Mendicant
Pushing The Limits

"Pushing the Limits of Reality and Virtual Reality to Another Level"
Epiphany Absolute
Registered User
Join date: 19 Jun 2005
Posts: 19
07-18-2005 14:41
I found my error...it was quite simply a matter of "don't script at 4am".
I had set the card value to 0 (to denote that it had been dealt) prior to setting the list data to return...which made it always 0 hehe
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
07-18-2005 15:16
One other nuance you should be aware of. When using List2* functions, you should always double-check how it is defined in the list versus what you're retrieving it as.

This is because certain data types don't convert properly when retrieved from the list in the wrong form. For example:

CODE
// Note this is a singular-element list with a string
list stringIt = ["<1,2,3>"];

// This would probably return <0,0,0>
vector vect = llList2Vector(stringIt,0);

// This would return the proper vector
vect = (vector)llList2String(stringIt,0);

Just a heads up.
_____________________
---