Getting into LiveCode for iOS? Ask your questions here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
dburdan
- Posts: 104
- Joined: Fri Jan 28, 2011 5:39 am
Post
by dburdan » Fri Feb 04, 2011 3:09 am
Hello, I am trying to repeat one part of a loop. For example:
Code: Select all
repeat with i = 1 to 4
put random(1,52) into x
if NoRepeatList contains x then
::Repeat this part of the loop::
end if
add x to NoRepeatList
end repeat
If that makes any sense I want it to check if one if the numbers is already in "NoRepeatList". If it is, I want it to retry that part of the loop again without starting the whole loop over. Does anybody know how I could go about doing this?
Thanks in advance
-
BvG
- VIP Livecode Opensource Backer

- Posts: 1239
- Joined: Sat Apr 08, 2006 1:10 pm
-
Contact:
Post
by BvG » Fri Feb 04, 2011 1:07 pm
repeat until x is not among the lines of NoRepeatList
put random(52) into x
end repeat
put x & return after NoRepeaList
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
dburdan
- Posts: 104
- Joined: Fri Jan 28, 2011 5:39 am
Post
by dburdan » Fri Feb 04, 2011 7:06 pm
That unfortunately doesn't work for my situation. I'm trying to generate 4 cards from a deck without generating the same card twice. This is what I have so far that works great but will occasionally generate the same card. Later on in the game I will need to generate 9 cards the same way.
Code: Select all
on generateAllCards
repeat with i = 1 to 4
put randomNum(1,52) into y
if y >9 then
put "50" & y into x
else
put "500" & y into x
end if
if i = 1 then
put x into vCard1
end if
if i = 2 then
put x into vCard2
end if
if i = 3 then
put x into vCard3
end if
if i = 4 then
put x into vCard4
end if
set the icon of button ("card" & i) to x
put GetValue(value(vCard1)) into field "vCard1"
put GetValue(value(vCard2)) into field "vCard2"
put GetValue(value(vCard3)) into field "vCard3"
put GetValue(value(vCard4)) into field "vCard4"
end repeat
end generateAllCards
-
BvG
- VIP Livecode Opensource Backer

- Posts: 1239
- Joined: Sat Apr 08, 2006 1:10 pm
-
Contact:
Post
by BvG » Fri Feb 04, 2011 8:01 pm
the code does what you want, but of course you need to add it into your existing code, duh.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
dburdan
- Posts: 104
- Joined: Fri Jan 28, 2011 5:39 am
Post
by dburdan » Fri Feb 04, 2011 8:11 pm
BvG wrote:the code does what you want, but of course you need to add it into your existing code, duh.
Then how would I implement it into the code above. I only want it to run 4 times & i don't want it to stop looping until it gets to 4. I don't want it to keep repeating until it generates the same number twice. I just want it generate a new number if the number it tried to generate has already been generated.
-
BvG
- VIP Livecode Opensource Backer

- Posts: 1239
- Joined: Sat Apr 08, 2006 1:10 pm
-
Contact:
Post
by BvG » Sat Feb 05, 2011 1:23 am
exactly. you want to repeat trying to generate the random number, until it is not among your existing numbers. then you do that four times.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode