Hello. I am having trouble scripting right now.
I want to have a script that acts like a bag of marbles. You choose one out of random and don't put it back. And then you repeat the same process until you have none left.
Let's say: I have 3 games included in a project (this is my true problem). I want players to only play a game once, and then the game will be restricted from being played again in the same round.
My question: Is it possible to script something like this? Or do I need to put in more details.
Offline
Ok, set up a list that has 3 values in it: 1,2,3
Make it so that the number of the game you play is pick random from (1) to (length of
list)
Then say you picked 1. First you would record a variable that holds the position that the 1 variable is in, then when the user is done with game 1, remove that value from the list and repeat the process until all the games are done.
It should look something like this:
when green flag clicked
set item 1 of gameList to 1
set item 2 of gameList to 2
set item 3 of gameList to 3
Repeat for length of gameList{
set randGame to (pick random from (1) to (length of gamelist)
if item randGame from gameList =1{
broadcast "play game1"
}
if item randGame from gameList =2{
broadcast "play game2"
}
if item randGame from gameList =3{
broadcast "play game3"
}
remove item randGame from gameList
}
That should work
Offline
BoltBaits solution was basically the same as mine. The difference is that mine calls a broadcast to play your game and mine automatically picks a new random game.
Neither scripts are perfect though, you won't be able to copy and put them in your projects and have them fully working. You have to have an understanding of how they work to make it work with the rest of your project.
Offline
archmage wrote:
BoltBaits solution was basically the same as mine.
I was just thinking that!
BTW, the technique that I showed is basically the same way I handle a deck of cards in any of my card games (black jack, cribbage solitaire, and the one I'm working on now... cribbage).
Offline
Glad to hear it!
BTW, the "Troubleshooting" section really is for problems with the development environment or online player. Your question should probably have been posted to the "All About Scratch" section.
It's not a big deal. But, when a mod sees this thread they may move it.
Last edited by BoltBait (2009-04-27 17:25:12)
Offline