Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-11-2004 16:44
When I write in VB, the way I shuffle a deck of cards is to randomize 52 variables, making sure no variable gets a duplicate integer.
Um... in other words, I declare variables for card1, card2, card3 ... card51, card52. Each variable is assigned a random value 1-52, with no duplicates.
Each individual card is assigned a number, and that number never changes. (i.e. 1=ace of spades, 2=two of spades...)
I use this method because some of the games I write are weird, and require the user to sometimes pick a card from the deck, and I need each and every face-down card to have a value defined at shuffle.
My question is, is it feasible to do it this way in LSL or will I be running into more difficulty than I want to?
|
Grim Lupis
Dark Wolf
Join date: 11 Jul 2003
Posts: 762
|
07-11-2004 17:05
Use a list to store the "deck" values. Then use llListRandomize() to "shuffle" the deck. Alternatively, you can use a more real-world solution, and write a method that does random position swapping within the list, but in LSL I think it would be highly inefficient.
_____________________
Grim
"God only made a few perfect heads, the rest of them he put hair on." -- Unknown
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
the example code isn't randomizing the list
07-11-2004 17:12
Cool, thanks for the link... I love the wiki!! The example code I copy and pasted from there is not randomizing the list though: list foo = ["LSL", "is", "teh", "sucks"]; list bar = llListRandomize(foo, 1); llSay(0,llList2CSV(foo)); I put it in a touch event and every time I touch the object, it says "LSL, is, teh, sucks". I reset and recompiled and it still is not randomizing it.
|
Grim Lupis
Dark Wolf
Join date: 11 Jul 2003
Posts: 762
|
Re: the example code isn't randomizing the list
07-11-2004 17:20
From: someone Originally posted by Aaron Levy Cool, thanks for the link... I love the wiki!!
The example code I copy and pasted from there is not randomizing the list though:
list foo = ["LSL", "is", "teh", "sucks"]; list bar = llListRandomize(foo, 1); llSay(0,llList2CSV(foo));
I put it in a touch event and every time I touch the object, it says "LSL, is, teh, sucks". I reset and recompiled and it still is not randomizing it. Umm... foo is the original list bar is the randomized list you're llSaying the foo list, not the bar list **Edit to note that I just noticed the bug is in the wiki sample code, it's not your bug. But it's still a bug, and easy to fix.
_____________________
Grim
"God only made a few perfect heads, the rest of them he put hair on." -- Unknown
|
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
|
07-11-2004 18:03
Yeah, I fixed the wiki. Sorry about that.
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-11-2004 18:47
Ok cool... the new corrected code works! (Thanks!)
|