Pages: 1 2
Topic closed
Do you guys know how to have the numbers 1 to 10 appear in a random order and not repeat any of the numbers. For instance a code that puts the numbers like this : 8,3,6,2,1,10,9,4,5,7, and each time I try it out the numbers are different
Offline
Here is one way to do it (in text, I'm too lazy to do scripts):
1. Create a list variable called MyList
2. Create a regular variable called MyValue
3. Create a regluar variable called MyIndex
This script will set up your list:
When Flag Pressed
Delete All of MyList
Set MyValue to 1
Repeat 10 times-----------
| Add MyValue to MyList
| Change MyValue by 1
----------------------------------
This script should be called when you want a number:
When I receive GetANumber
Set MyIndex to (Random 1 to Length of MyList)
Set MyValue to (Item MyIndex of MyList)
Delete item MyIndex of MyList
At this point, the variable MyValue has a random value from 1 to 10. You can call it 10 times and never get a repeat. The way you call this is to use the "Broadcast GetANumber and wait" block.
This is exactly how I handle a deck of cards in all of my various card games.
Hope this helps.
Last edited by BoltBait (2009-09-25 17:57:52)
Offline
BoltBait wrote:
Here is one way to do it (in text, I'm too lazy to do scripts):
1. Create a list variable called MyList
2. Create a regular variable called MyValue
3. Create a regluar variable called MyIndex
This script will set up your list:
When Flag Pressed
Delete All of MyList
Set MyValue to 1
Repeat 10 times-----------
| Add MyValue to MyList
| Change MyValue by 1
----------------------------------
This script should be called when you want a number:
When GetANumber is received
Set MyIndex to Random 1 to Length of MyList
Set MyValue to Item MyIndex of MyList
Delete item MyIndex of MyList
At this point, the variable MyValue has a random value from 1 to 10. You can call it 10 times and never get a repeat.
This is exactly how I handle a deck of cards in all of my various card games.
Hope this helps.
Too put it in block terms:
<when green flag clicked>
[delete all of [My List]]
<set{ My value }to( 1
<repeat( 10
[add (My Value) to [My List]]
<change{ My Value }by( 1
<end>
<when I receive[ Get A Number
<set{ My Index }to( <pick random( 1 )to( length of [My List]
<set{ My Value }to( item (My Index) of [My List]
[Delete (My Index) of [My List)]
Last edited by The-Whiz (2009-09-25 18:03:28)
Offline
sorry, but the numbers still repeat when i try them out. need a clearer explaination
Offline
Hmm...
[blocks]
<when green flag clicked>
[Delete all of List]
<repeat( 10 )>
<set{ Number }to( <pick random( 1 )to( 10 )>
<if>[List contains <{ Number }> ]
(Keep blank here.)
<else>
[Add <{ Number }> to List]
<end>
[/blocks]
Hope that helps... I'll post a project later.
Offline
Project, some stuff has been changed from the script above, but it still works. http://scratch.mit.edu/projects/Magnie/695598
Offline
magnie is there a way i can send you this project so you can fix the issue i'm having. basically what i want is to have 10 questions appear in a random order each time you retry it. I have everything already finished and the questions are a different sprite and they correspond to a number from 1 to 10. I'm not an expert on scratch so I'm pretty sure you won't have trouble understanding the codes I wrote for this project. Please can you help me or anyone else who wants to have a look through at my project, give me your email address. please i am desperate.
Offline
Why can't you just post it? *sigh* I can't give you any Email on the forums, so you need to create a gallery.
Last edited by Magnie (2009-09-26 15:42:43)
Offline
Ok i'll post it
Offline
Thanks.
Offline
Here you go: Just download it and see if you can do it.
http://scratch.mit.edu/projects/legendzkillar/695626
Offline
Yeah, got it, it's gona take some time to get it to work. (Needs to think through your programming to understand it. )
Offline
Lol, you can take all the time you want. I really hope your post doesn't contain this message: "I couldn't do it, sorry", lol anyway just do your best, your projects are impressive btw.
Offline
Thanks! It will take me a day or two, or just 30 minutes. I think I found what you're doing but I don't know the answers to these questions. xD
Offline
Knowing the answers would actually help a lot, all I need to do is test it a few times and it's ready.
Offline
you wants answers I'll give you the answers
B, A, C, A, B, A, D, A, B, D
Offline
Lol thanks!
Offline
Okay, I have one glitch I've noticed, the first 3-4 questions don't say correct or incorrect. (They don't say ANYTHING) and sometimes when you get the correct answer it will say That's Correct! then it will say The correct answer is [Letter]! <- It says that RIGHT after it says the correct answer. I'll dig deeper into the code and see where it's broken.
Offline
One thing if you haven't noticed there are codes in the background(stage) sprite also. Those codes are pretty important. They have the answers set out in numbers, A= 1, B=2..etc I think if you have the questions in random order then you have to find a way to have the answers follow the right questions.
Offline
I can't be on anymore right now, Hopefully on Monday or tonight I'll get this done, I'll upload the project so far. http://scratch.mit.edu/projects/Magnie/695674 <- There's the project so far, but not done.
Offline
It would be great if it was done by sunday, but monday however will lead to my death. Unfortunately, it needs to be done before monday, if you can finish in sunday you will still be awesome.
Offline
Yeah, that's what I thought, but I think it's done. It's just I can't go on Sunday, so that's why I said Monday. But here's the project: http://scratch.mit.edu/projects/Magnie/695787
Offline
ohh so close, but unfortunately the answers aren't matching with the questions. even when i answer it right it says wrong. I might just get rid of the whole "the correct answer is..." to make it simpler. Your help would be nice also, even on monday.
Offline
Hmm... Yeah, I was gona say why have it say "Correct!' or 'Incorrect!' but does it say the right amount correctly at the end?
Offline
Hopefully my modified version of Magnie’s project based on your project is what you want.
http://scratch.mit.edu/projects/DigimathFixit/696214
The fonts are not the same as your original project but keeping fonts the same between re-mixed projects appears to be a problem in Scratch.
Offline
Topic closed
Pages: 1 2