Flasher Archive
[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]
Subject: | Re: FLASH: set variable randomly, numbers should only be taken once |
From: | TGunn |
Date: | Tue, 11 Jul 2000 21:59:33 +0100 |
>i need to set 5 variables to random number out of 56, the thing is that
>every number should only be taken once, how do i do that? that's how far i
>got:
>
>Set Variable: "a" = (Random(56)+1)
>Set Variable: "b" = (Random(56)+1)
>Set Variable: "c" = (Random(56)+1)
>Set Variable: "d" = (Random(56)+1)
>Set Variable: "e" = (Random(56)+1)
>
>nadia
Hi Nadia :)
The script below does something similar to what you're looking for. (btw,
sorry to all for the byte heavy msg). It's in VBScript(ASP) but you can
easily pick apart the logic and translate it into ActionScript. I kept it
in VBs b/c I figured IIS could crank faster then Flash.
The script is for a blackjack game I did a few months back
http://www.xyzwebdesign.com/blackjack/new/blackjacklogon.asp ), anyone on a
slow connection out there wanna see if you can spot the blurp? hint:
face-cards. Think I'm going to have to load the face-card images within the
main movie, duplicate &set x,y pos over the card back when needed,
otherwise they're just a bit too heavy to load on demand... another day,
when it's for $ perhaps... he he..
hope this helps ya
"Who needs daytime soaps or comedy central when you've got the flasher
list?"
Tony Gunn
webweaverxyzwebdesign [dot] com
----------------------------------------------------------------------------
-------
<%@ Language=VBScript %>
<%
'grabs 1 card
function getCard()
randomize
lcount = (125 * rnd) * 1
for x = 0 to Cint(lcount)
val = (52 * rnd) * 1
if val > 51 then
val = 52.0
end if
if val < 1 then
val = 1.0
end if
next
getCard = CInt(val)
end function
'assigns file name to the card num
'cases are out of order to promote further randomness
function assignValue(num)
select case num
case 1 assignValue = "2d.swf"
case 11 assignValue = "2h.swf"
case 21 assignValue = "2c.swf"
case 31 assignValue = "2s.swf"
case 41 assignValue = "3d.swf"
case 51 assignValue = "3h.swf"
case 2 assignValue = "3c.swf"
case 12 assignValue = "3s.swf"
case 22 assignValue = "4d.swf"
case 32 assignValue = "4h.swf"
case 42 assignValue = "4c.swf"
case 52 assignValue = "4s.swf"
case 13 assignValue = "5d.swf"
case 23 assignValue = "5h.swf"
case 33 assignValue = "5c.swf"
case 43 assignValue = "5s.swf"
case 4 assignValue = "6d.swf"
case 14 assignValue = "6h.swf"
case 24 assignValue = "6c.swf"
case 34 assignValue = "6s.swf"
case 44 assignValue = "7d.swf"
case 5 assignValue = "7h.swf"
case 15 assignValue = "7c.swf"
case 25 assignValue = "7s.swf"
case 35 assignValue = "8d.swf"
case 45 assignValue = "8h.swf"
case 6 assignValue = "8c.swf"
case 16 assignValue = "8s.swf"
case 26 assignValue = "9d.swf"
case 36 assignValue = "9h.swf"
case 46 assignValue = "9c.swf"
case 7 assignValue = "9s.swf"
case 17 assignValue = "10d.swf"
case 27 assignValue = "10h.swf"
case 37 assignValue = "10c.swf"
case 47 assignValue = "10s.swf"
case 8 assignValue = "jd.swf"
case 18 assignValue = "jh.swf"
case 28 assignValue = "jc.swf"
case 38 assignValue = "js.swf"
case 48 assignValue = "qd.swf"
case 9 assignValue = "qh.swf"
case 19 assignValue = "qc.swf"
case 29 assignValue = "qs.swf"
case 39 assignValue = "kd.swf"
case 49 assignValue = "kh.swf"
case 10 assignValue = "kc.swf"
case 20 assignValue = "ks.swf"
case 30 assignValue = "ad.swf"
case 40 assignValue = "ah.swf"
case 50 assignValue = "ac.swf"
case 3 assignValue = "as.swf"
'defalut to 2s
case else assignValue = "2s.swf"
end select
end function
dc2flag = false
dc3flag = false
dc4flag = false
dc5flag = false
pc1flag = false
pc2flag = false
pc3flag = false
pc4flag = false
pc5flag = false
pc6flag = false
pc7flag = false
pc8flag = false
pc9flag = false
dc6flag = false
dc7flag = false
dc8flag = false
dc9flag = false
dc10flag = false
pc10flag = false
'get unique card, 1 deck in this game so no repeats
dc1 = getCard()
do until dc2flag = true
dc2 = getCard()
if dc2 <> dc1 then
dc2flag = true
end if
loop
do until dc3flag = true
dc3 = getCard()
if dc3 <> dc1 and dc3 <> dc2 then
dc3flag = true
end if
loop
do until dc4flag = true
dc4 = getCard()
if dc4 <> dc1 and dc4 <> dc2 and dc4 <> dc3 then
dc4flag = true
end if
loop
do until dc5flag = true
dc5 = getCard()
if dc5 <> dc1 and dc5 <> dc2 and dc5 <> dc3 and dc5<> dc4 then
dc5flag = true
end if
loop
do until pc1flag = true
pc1 = getCard()
if pc1 <> dc1 and pc1 <> dc2 and pc1 <> dc3 and pc1 <> dc4 and pc1 <> dc5
then
pc1flag = true
end if
loop
do until pc2flag = true
pc2 = getCard()
if pc2 <> dc1 and pc2 <> dc2 and pc2 <> dc3 and pc2 <> dc4 and pc2 <> dc5
and pc2 <> pc1 then
pc2flag = true
end if
loop
do until pc3flag = true
pc3 = getCard()
if pc3 <> dc1 and pc3 <> dc2 and pc3 <> dc3 and pc3 <> dc4 and pc3 <> dc5
and pc3 <> pc1 and pc3 <> pc2 then
pc3flag = true
end if
loop
do until pc4flag = true
pc4 = getCard()
if pc4 <> dc1 and pc4 <> dc2 and pc4 <> dc3 and pc4 <> dc4 and pc4 <> dc5
and pc4 <> pc1 and pc4 <> pc2 and pc4 <> pc3 then
pc4flag = true
end if
loop
do until pc5flag = true
pc5 = getCard()
if pc5 <> dc1 and pc5 <> dc2 and pc5 <> dc3 and pc5 <> dc4 and pc5 <> dc5
and pc5 <> pc1 and pc5 <> pc2 and pc5 <> pc3 and pc5 <> pc4 then
pc5flag = true
end if
loop
do until pc6flag = true
pc6 = getCard()
if pc6 <> dc1 and pc6 <> dc2 and pc6 <> dc3 and pc6 <> dc4 and pc6 <> dc5
and pc6 <> pc1 and pc6 <> pc2 and pc6 <> pc3 and pc6 <> pc4 and pc6 <> pc5
then
pc6flag = true
end if
loop
do until pc7flag = true
pc7 = getCard()
if pc7 <> dc1 and pc7 <> dc2 and pc7 <> dc3 and pc7 <> dc4 and pc7 <> dc5
and pc7 <> pc1 and pc7 <> pc2 and pc7 <> pc3 and pc7 <> pc4 and pc7 <> pc5
and pc7 <> pc6 then
pc7flag = true
end if
loop
do until pc8flag = true
pc8 = getCard()
if pc8 <> dc1 and pc8 <> dc2 and pc8 <> dc3 and pc8 <> dc4 and pc8 <> dc5
and pc8 <> pc1 and pc8 <> pc2 and pc8 <> pc3 and pc8 <> pc4 and pc8 <> pc5
and pc8 <> pc6 and pc8 <> pc7 then
pc8flag = true
end if
loop
do until pc9flag = true
pc9 = getCard()
if pc9 <> dc1 and pc9 <> dc2 and pc9 <> dc3 and pc9 <> dc4 and pc9 <> dc5
and pc9 <> pc1 and pc9 <> pc2 and pc9 <> pc3 and pc9 <> pc4 and pc9 <> pc5
and pc9 <> pc6 and pc9 <> pc7 and pc9 <> pc8 then
pc9flag = true
end if
loop
do until dc6flag = true
dc6 = getCard()
if dc6 <> dc1 and dc6 <> dc2 and dc6 <> dc3 and dc6 <> dc4 and dc6 <> dc5
and dc6 <> pc1 and dc6 <> pc2 and dc6 <> pc3 and dc6 <> pc4 and dc6 <> pc5
and dc6 <> pc6 and dc6 <> pc7 and dc6 <> pc8 and dc6 <> pc9 then
dc6flag = true
end if
loop
do until dc7flag = true
dc7 = getCard()
if dc7 <> dc1 and dc7 <> dc2 and dc7 <> dc3 and dc7 <> dc4 and dc7 <> dc5
and dc7 <> pc1 and dc7 <> pc2 and dc7 <> pc3 and dc7 <> pc4 and dc7 <> pc5
and dc7 <> pc6 and dc7 <> pc7 and dc7 <> pc8 and dc7 <> pc9 and dc7 <> dc6
then
dc7flag = true
end if
loop
do until dc8flag = true
dc8 = getCard()
if dc8 <> dc1 and dc8 <> dc2 and dc8 <> dc3 and dc8 <> dc4 and dc8 <> dc5
and dc8 <> pc1 and dc8 <> pc2 and dc8 <> pc3 and dc8 <> pc4 and dc8 <> pc5
and dc8 <> pc6 and dc8 <> pc7 and dc8 <> pc8 and dc8 <> pc9 and dc8 <> dc6
and dc8 <> dc7 then
dc8flag = true
end if
loop
do until dc9flag = true
dc9 = getCard()
if dc9 <> dc1 and dc9 <> dc2 and dc9 <> dc3 and dc9 <> dc4 and dc9 <> dc5
and dc9 <> pc1 and dc9 <> pc2 and dc9 <> pc3 and dc9 <> pc4 and dc9 <> pc5
and dc9 <> pc6 and dc9 <> pc7 and dc9 <> pc8 and dc9 <> pc9 and dc9 <> dc6
and dc9 <> dc7 and dc9 <> dc8 then
dc9flag = true
end if
loop
do until dc10flag = true
dc10 = getCard()
if dc10 <> dc1 and dc10 <> dc2 and dc10 <> dc3 and dc10 <> dc4 and dc10 <>
dc5 and dc10 <> pc1 and dc10 <> pc2 and dc10 <> pc3 and dc10 <> pc4 and dc10
<> pc5 and dc10 <> pc6 and dc10 <> pc7 and dc10 <> pc8 and dc10 <> pc9 and
dc10 <> dc6 and dc10 <> dc7 and dc10 <> dc8 and dc10 <> dc9 then
dc10flag = true
end if
loop
do until pc10flag = true
pc10 = getCard()
if pc10 <> dc1 and pc10 <> dc2 and pc10 <> dc3 and pc10 <> dc4 and pc10 <>
dc5 and pc10 <> pc1 and pc10 <> pc2 and pc10 <> pc3 and pc10 <> pc4 and pc10
<> pc5 and pc10 <> pc6 and pc10 <> pc7 and pc10 <> pc8 and pc10 <> pc9 and
pc10 <> dc6 and pc10 <> dc7 and pc10 <> dc8 and pc10 <> dc9 and pc10 <>
dc10 then
pc10flag = true
end if
loop
%>
<%
' convert num into it's swf equivalent
card1 = assignValue(dc1)
card2 = assignValue(dc2)
card3 = assignValue(dc3)
card4 = assignValue(dc4)
card5 = assignValue(dc5)
dcard1 = assignValue(pc1)
dcard2 = assignValue(pc2)
dcard3 = assignValue(pc3)
dcard4 = assignValue(pc4)
dcard5 = assignValue(pc5)
card6 = assignValue(pc6)
card7 = assignValue(pc7)
card8 = assignValue(pc8)
card9 = assignValue(pc9)
card10 = assignValue(pc10)
dcard6 = assignValue(dc6)
dcard7 = assignValue(dc7)
dcard8 = assignValue(dc8)
dcard9 = assignValue(dc9)
dcard10 = assignValue(dc10)
%>
<%'pack em up & ship em out%>
<%="card1="+server.URLEncode(card1)%>
<%="&card2="+server.URLEncode(card2)%>
<%="&card3="+server.URLEncode(card3)%>
<%="&card4="+server.URLEncode(card4)%>
<%="&card5="+server.URLEncode(card5)%>
<%="&card6="+server.URLEncode(dcard1)%>
<%="&card7="+server.URLEncode(dcard2)%>
<%="&card8="+server.URLEncode(dcard3)%>
<%="&card9="+server.URLEncode(dcard4)%>
<%="&card10="+server.URLEncode(dcard5)%>
<%'assuming cookies are enabled, else the movie will have to catch it &
assign defalut values but no score tracking%>
<%="&credits="+server.URLEncode(Session("credits"))%>
<%="&player="+server.URLEncode(Session("nickname"))%>
<%="&new="+server.URLEncode(session("new"))%>
<%Response.End%>
flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and the Flash(tm) Film Festival
July 24-26, 2000, NEW YORK CITY, Hammerstein Ballroom
www.flashforward2000.com
Produced by United Digital Artists and lynda.com
Sponsored by Macromedia, Adobe Systems, Fusion, Inc, AtomFilms,
shockwave.com and Electric Rain.
1.877.4.FLASH.4 or (1.805.640.6679 outside the US and Canada)
Register before June 30 and save $200!!-- www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpchinwag [dot] com
Replies
Re: FLASH: set variable randomly, number, nadia
[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]