Jump to content

Trying to make a simple card draw deck


HarrisonMcKenzie
 Share

You are about to reply to a thread that has been inactive for 1508 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

The title basically says it. I'm working on a manual board game (where users have to use their brains instead of relying on automation). What I'm in need of is to "draw" a card from a deck. This can either be to rez the card on or near the deck, or just deliver it to the person who drew. Once drawn, that card is out of the deck and cannot be drawn again until the deck is reset (the card put back into the contents, the deck is rerezzed, etc). The cards will be prims, so I'm not just looking for a random number generator that gives me something like "2 Club" in chat.

Could anyone point me in a direction? I can't imagine this being a terribly difficult thing to do, but I'm not very familiar enough with LSL and haven't been able to find someone to help in-world.

Thanks in advance.

Link to comment
Share on other sites

could make it like the card game Fish

linkset of cards face down

touch a card and it flips over

would need a list of length(link numbers) with an initial shuffle on game reset

list cards = llListRandomize(["Ace", "Two" , "Three", ....], 1);


touch(...)
{
    integer link = llDetectedLinkNum(0);
    string card = llList2String(cards, link);
    
    ... display card texture on link face ...

    ... do something with player having card: Ace, Two, etc
}

 

Link to comment
Share on other sites

So there are several things to consider with your current approach. If you aim to have each card be its own object that can potentially be rezzed or given to a player, you probably would want to set the next-owner-permissions on each card to no-copy. That way when the card is given to a player, the new permissions kick in and they won't be able to keep multiple copies (saves on clutter and possible cheating). Meanwhile, the deck would retain the original collection of cards in its own inventory.

You mentioned that you want a very manual feel to the game - to the point where cards dealt are actually removed from the deck's inventory and must be put back in afterwards. You can do this... but I think it might be more trouble than its worth to reset the game. You'd need to code failsafes on what to do if not all cards are put back in, or stuff other than the expected cards are dropped into the deck. And again, while you probably can do this - I think it would be much more trouble than it's worth, especially for a beginner project. I think we can achieve a similar feel without necessarily messing with the deck's own inventory. Keeping that static would make things easier for you.

Script-wise, you'll need to keep track of all the cards, so that you don't accidentally deal a card that has already been given out. I believe the simplest solution would be to construct a list of all card names in script memory. Assuming you have all the cards already in the deck's inventory, you can generate this list by using a loop and llGetInventoryName. There is an example on the linked wiki page on how to loop over the contents of an object's inventory. It would be good to do this in the state_entry event - i.e. when the script first starts/restarts, that was you'll always be starting with a full deck.

Then whenever you need to draw a card, you will essentially generate a random number between zero and the current length of the card-name-list minus one (because lists are zero-indexed). Use this number as an index into the card-name-list and select a card name with llList2String. You can then give a copy of the card, referenced by the name we just selected using llGiveInventory. Finally, delete that item from the list in memory so we don't select it again. There is a user created function you can find on the wiki to do just that: ListItemDelete. It's okay that we delete the item from the list, because we can easily reconstruct it when we restart the script as per my mention of the state_entry event. This is much easier to recreate than say relying on players to put all the cards back manually.

This is just one suggestion, there are many  ways to approach solving this problem. Hopefully this will give you a starting point. In general, reading through the wiki as a whole is a good idea. There's a lot there, but it's good knowledge. You may even want to skim through some beginner tutorials to get more familiar with the basics. Good luck!

Edited by Fenix Eldritch
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1508 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...