Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two math questions 1

Status
Not open for further replies.

Butters261285

Programmer
Jan 2, 2006
29
GB
ok two questions for anyone clever enough to answer as im stumped ^_^

Q1.

Say i have values 1-10 and i have variables box1 - box10

how do i set a script that on enter frame it sets box1 to a random one of those values, then sets box2 to one of the remaining 9 values that are left and so on til box10 is given the last one.?

---------------------------------------------------------

Q2.

In the main game the values of 1-10 will be more like cash values like $10 $100 $25000 ect.... so how would i make a code so that after 3 boxes have been opened...it added together all the remaining values and divided by how many boxes there are left to get an average...then pick a random value within a range of this value
-----------------------------------------------------------

ill add some coding to this when i get a minute...

thanks

Peter Butler
 
I'll do something like this to accomplish the first one:

[tt]-- Movie script
on populateVars
global gBoxList
gBoxList = []
numList = []
repeat with i = 1 to 10
numList = i
end repeat
repeat while numList.count
randomNum = random(numList.count)
gBoxList.append(numList[randomNum])
numList.deleteAt(randomNum)
end repeat
put("gBoxList:" && gBoxList)
end populateVars
--[/tt]

Then you just call populateVars() and get the result such as [tt]"gBoxList: [2, 6, 8, 10, 3, 4, 7, 5, 9, 1]"[/tt].

To access a variable, use [tt]gBoxList[index][/tt]. For example if you want to get the box no.6:

[tt]--
put gBoxList[6]
-- 4
--[/tt]

Kenneth Kawamoto
 
URL]


Hey kenneth, thanks for your coding but im fairly new to lingo so that kind of went right over my head :S

Let me explain what im trying to achieve (i made a picture too which may help-see link at beginning of post!)

I am trying to make a Director game for the game show Deal or No Deal. In the English version of this game there are 22 sealed red boxes (see fig 1) each with a secret value (see fig 3).

Basically at the start of the show, someone is picked at random and comes to the front with their box. They are the person who plays.

Because all boxes are sealed nobody know what is in each one. The order of play is as figure 2 shows.

When the player picks a box it is removed from the values list. after the first 5 boxes, the dealer calls and offers the player a certain amount of cash to try and get them to deal and essentially sell their box.

The whole game basically revolves around the player trying to narrow the values down so that they are really high ones left so that th ebanker panics and offers a large amount. Sometimes players play right down til the last two boxes...at which point they can get the chance to swap their box with the one left. and then open the last one.

-----------------------------------------------------------

The only thing i seem to get the hang of in director lingo is how to use global variables..

i would probably start it as something like

--code in the first frame--

global gBox1, gBox2, gBox3, gBox4, gBox5, gBox6, gBox7, gBox8, gBox9, gBox10, gBox11, gBox12, gBox13, gBox14, gBox15, gBox16, gBox17, gBox18, gBox19, gBox20, gBox21, gBox22,

on enterFrame
set gBox1 = [one value from a list of all the values]
set gBox2 = etc etc
all the way down to
gBox22

--Perhaps if rather than trying to randomly generate the box numbers, i just had a few set variables

so if i had one variable where the boxes all equaled certain amounts specifeid by me, then anothe rone with a different combination...and so on... then at the beginning of the game it just randomly picks one of these variables and sets the bowxes to them... how woudl i do that?
 
I've never watched "Deal or no deal" (your link to the JPEG doesn't work, by the way.)

However, instead of doing:

[tt]--
global gBox1, gBox2, gBox3, gBox4, gBox5, gBox6, gBox7, gBox8, gBox9, gBox10, gBox11, gBox12, gBox13, gBox14, gBox15, gBox16, gBox17, gBox18, gBox19, gBox20, gBox21, gBox22,

on enterFrame
gBox1 = "£100"
gBox2 = "£200"
-- all the way down to gBox22
end enterFrame
--[/tt]

You can do:

[tt]--
global gBoxList

on enterFrame
gBoxList = ["£100", "£200", ... "£2200"]
end enterFrame
--[/tt]

Or:

[tt]--
global gBoxList

on enterFrame
gBoxList = [#Box1: "£100", #Box2: "£200", ... #Box22: "£2200"]
end enterFrame
--[/tt]

It's far easier to manage, and less typing!

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top