Opening random cards
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Opening random cards
I have 5 cards cards and I want open cardss random, but I want exclude cards that have been already open ??
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Opening random cards
Hi.
So does this make any sense:
Or this, a bit more robust:
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
So does this make any sense:
Code: Select all
go card random(5)
Code: Select all
go card random(the number of cards)
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
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Opening random cards
I think "any" would work here was well:
go any card
go any card
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Opening random cards
..........
Last edited by [-hh] on Wed Aug 13, 2014 3:45 pm, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 29
- Joined: Tue Jun 27, 2006 8:35 pm
- Location: Bellingham, WA USA
- Contact:
Re: Opening random cards
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
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!
...now with 20% less chalk dust!
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Opening random cards
..........
Last edited by [-hh] on Wed Aug 13, 2014 3:46 pm, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Opening random cards
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
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
Re: Opening random cards
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?
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Opening random cards
How did you manage to find this thread after more than half a decade?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Opening random cards
Hah...that would be curtesy of a google search. I was wondering if anyone would answer after so many years have passed.FourthWorld wrote: ↑Fri Dec 04, 2020 3:19 amHow did you manage to find this thread after more than half a decade?
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Opening random cards
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
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
Re: Opening random cards
Cool. Thanks, Craig!
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Opening random cards
You are very welcome. But since you found this thread in the ether, read it from the top.
Craig
Craig
-
- Livecode Opensource Backer
- Posts: 9287
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Opening random cards
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 146 times
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Opening random cards
I am thinking more along the lines of:
On a new card make a button and two fields. Put this into fld 1:
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
On a new card make a button and two fields. Put this into fld 1:
Put this into the script of the button:A,B,C,D,E,F,G,X,Y,Z
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
Craig