Opening random cards

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Role33
Posts: 1
Joined: Tue Jul 22, 2014 11:18 pm

Opening random cards

Post by Role33 » Tue Jul 22, 2014 11:27 pm

I have 5 cards cards and I want open cardss random, but I want exclude cards that have been already open ??

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7311
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Opening random cards

Post by dunbarx » Wed Jul 23, 2014 4:08 am

Hi.

So does this make any sense:

Code: Select all

go card random(5)
Or this, a bit more robust:

Code: Select all

go card random(the number of cards)
And about that open once and forget thing. Conceptually, what would you think? Perhaps to mark a card that had already been opened somehow, and preclude it from being opened again? How about creating a list of card references, choose one at random, and then delete that reference from the list? Could you do this easily with a list of card numbers? Watch out for that last one.

All these and more are possible, and you will soon learn how to implement them. The thinking about a method is just as important as learning the tools to make your ideas real. Where are you in learning LC?

So, where shall we begin? By that I mean write back with your thoughts.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8295
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Opening random cards

Post by FourthWorld » Wed Jul 23, 2014 6:25 am

I think "any" would work here was well:

go any card
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Opening random cards

Post by [-hh] » Wed Jul 23, 2014 8:47 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:45 pm, edited 1 time in total.
shiftLock happens

scott_morrow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Tue Jun 27, 2006 8:35 pm
Location: Bellingham, WA USA
Contact:

Re: Opening random cards

Post by scott_morrow » Thu Jul 24, 2014 1:11 am

In order to keep from visiting the same card twice (at least until they are all visited) one method would be, as Craig pointed out, to keep a list of card names or numbers and remove them from the list each time you visit one.

For instance:

on openStack
-- initialize
set the uAvailableCards of this stack to "1,2,3,4,5"
end openStack

on mouseUp
set the itemDel to COMMA
put the uAvailableCards of this stack into tAvailableCards
put the number of items of tAvailableCards into tNumOfItems
put random(tNumOfItems) into tPickedItemNum
put item tPickedItemNum of tAvailableCards into tTargetCardNumber
delete item tPickedItemNum of tAvailableCards
set the uAvailableCards of this stack to tAvailableCards
go card tTargetCardNumber
end mouseUp

This still leaves some work in checking to see if the list is empty and refilling it (or whatever) once all the possible picks are used up
Elementary Software
...now with 20% less chalk dust!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Opening random cards

Post by [-hh] » Thu Jul 24, 2014 1:23 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:46 pm, edited 1 time in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7311
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Opening random cards

Post by dunbarx » Thu Jul 24, 2014 4:59 am

Hermann's method is fine indeed. But whether you use a self extinguishing list or a randomized read-through-once list is a matter of style.

Here is the fun thing to consider. How do we keep track of either method? In other words, how do we either index the random list, or decimate the self extinguishing one? If I read you correctly, you will click on an image now and then, that is, from the interface. You are not setting in motion a handler that can do its own bookkeeping. So this information has to be stored somewhere or somehow, and updated at each event.

Let's hear what you come up with. For both, please.

Craig

KLevins
Posts: 3
Joined: Sat Jul 11, 2020 4:45 am

Re: Opening random cards

Post by KLevins » Fri Dec 04, 2020 2:43 am

FourthWorld wrote:
Wed Jul 23, 2014 6:25 am
I think "any" would work here was well:

go any card
How do you keep from opening the same card 2x in a row. I am using "go any card," which works pretty well, but occasionally it will direct me to the same card again. The problem is the button(s) on that card have already been clicked and "disabled" and my reset of the card doesn't happen unless the card is reopened (since my reset of the buttons is scripted on "preOpen card"). Any thoughts on how to fix this?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8295
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Opening random cards

Post by FourthWorld » Fri Dec 04, 2020 3:19 am

How did you manage to find this thread after more than half a decade?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

KLevins
Posts: 3
Joined: Sat Jul 11, 2020 4:45 am

Re: Opening random cards

Post by KLevins » Fri Dec 04, 2020 3:24 am

FourthWorld wrote:
Fri Dec 04, 2020 3:19 am
How did you manage to find this thread after more than half a decade?
Hah...that would be curtesy of a google search. I was wondering if anyone would answer after so many years have passed. :P

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7311
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Opening random cards

Post by dunbarx » Fri Dec 04, 2020 4:25 am

Hi.

I do this now and then. I always make a list of items like "1,2,3,4,5".

When you get a "any" item of that list, say, 4, you go to card 4, and delete the 4 from the list. Then when you get any item again, you are guaranteed not to duplicate that 4.

Craig

KLevins
Posts: 3
Joined: Sat Jul 11, 2020 4:45 am

Re: Opening random cards

Post by KLevins » Sat Dec 05, 2020 7:47 pm

dunbarx wrote:
Fri Dec 04, 2020 4:25 am
Hi.

I do this now and then. I always make a list of items like "1,2,3,4,5".

When you get a "any" item of that list, say, 4, you go to card 4, and delete the 4 from the list. Then when you get any item again, you are guaranteed not to duplicate that 4.

Craig
Cool. Thanks, Craig!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7311
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Opening random cards

Post by dunbarx » Sun Dec 06, 2020 5:26 am

You are very welcome. But since you found this thread in the ether, read it from the top. 8)

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5262
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Opening random cards

Post by richmond62 » Sun Dec 06, 2020 11:43 am

Screenshot 2020-12-06 at 12.41.39.png
-

Code: Select all

on mouseUp
   put random(5) into RR
   if RR is not in fld "RANDY" of card 1 then
      put 1 into LYNE
      repeat until line LYNE of fld "RANDY" of card 1 is empty
         add 1 to LYNE
      end repeat
      put RR into line LYNE of fld "RANDY" of card 1
      go to card RR
   end if
end mouseUp
Attachments
RANDOM.livecode.zip
Here's the stack.
(1.27 KiB) Downloaded 12 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7311
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Opening random cards

Post by dunbarx » Mon Dec 07, 2020 2:21 am

I am thinking more along the lines of:

On a new card make a button and two fields. Put this into fld 1:
A,B,C,D,E,F,G,X,Y,Z
Put this into the script of the button:

Code: Select all

on mouseUp
   get random(the number of items of fld 1)
   put item it of fld 1 into fld 2
   delete item it of fld 1
end mouseUp
Click the mouse a few times. Random choices from fld 1 appear in fld 2, and that option is deleted. Whatever functionality you use, as opposed to simply loading items somewhere, can be implemented in the same way.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”