This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-17 23:17:15

youtube_com
New Scratcher
Registered: 2012-03-17
Posts: 4

need HELP with scratch (PLEASE !)

i'm having trouble making a scratch script for a game called "Nim". You can look up the game on google to see what it is. I'm suppose to make a list (number of piles and how many stones in each pile), which I did, and then make the player choose a pile number, which I already. But then, after choosing the pile number, the player has to choose how many 'stones', in this case the numbers in the list to take out. Ex, if in pile number 3 (item number 3 on the list) had 6 stones (integer 6), and then the player chooses to take out 2 stones, that pile number (item number 3 on the list) would change from 6 to 4. This is the part i'm having trouble with, please help!

Offline

 

#2 2012-03-17 23:23:56

MaxFlyboy
Scratcher
Registered: 2011-11-07
Posts: 100+

Re: need HELP with scratch (PLEASE !)

Well if the list is like this

1:stone
2:stone
3:stone
4:stone
5:stone
6:stone

you could just use this block

delete item (1 v) of [stones v]
twice

Last edited by MaxFlyboy (2012-03-17 23:24:20)


http://cdn.voodoofilm.org/images/upload/thumb/viral-video-2011.jpg click the picture for an AMV

Offline

 

#3 2012-03-17 23:25:12

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: need HELP with scratch (PLEASE !)

Use this.

ask [How many stones would you like to take?] and wait
replace item (pile#) of [stonepiles v] with ( (item (pile#) of [stonepiles v] ) - (answer) )
'pile#' is the pile that the player has chosen.
'stonepiles' is the list mentioned which contains the number of stones in each pile.

Last edited by trinary (2012-03-17 23:26:45)


http://trinary.tk/images/signature_.php

Offline

 

#4 2012-03-17 23:52:59

youtube_com
New Scratcher
Registered: 2012-03-17
Posts: 4

Re: need HELP with scratch (PLEASE !)

@MaxFlyboy I don't get quite what you mean, and the list is not in order as well. the list could be 1, 3, 4, 6, 7, etc.

@trinary i've tried your method before, but it'll only work if the list is in order, i.e..
1. 1
2. 2
3. 3
4. 4

But the user actually generates the list, the user picks the number of piles and the number inside each pile. Ex. the list could be something like this.

1. 4
2. 6
3. 8
4. 2

I've already figured out how to do this. after this, the user picks which pile to take a stone from. Which i've done using the above method of 'replace item'. But when it comes to "replace WITH", I'm not sure what to put inside the 'with'. Say the user chooses to pick pile number 2 in the above example, there are 6 stones in it. And then say the user chooses to take out 2 stones from that pile, this is where I'm having trouble with. I can't make scratch know there is 6 stones in pile number 2. How do I make scratch recognize how many stones there are in the pile that the user chooses? I would really appreciate your further help!

Offline

 

#5 2012-03-18 02:35:54

itsmomito
Scratcher
Registered: 2008-03-28
Posts: 100+

Re: need HELP with scratch (PLEASE !)

Hmm, I think I could help. Could you post the project so I could think up something?

From what I understand, make a Pile # List  and # Of Stones List

So if the user chose a pile #, for example 6, it would scroll through the Pile # List until it was found. However, I am not sure if you could correspond the # of Stones list to the pile # list. That is why I would like to see the actual file and see how the whole thing works. Here is a sample:

Pile # List                # Of Stones List

item1  =  1               item1 = 3
item2  =  3               item2 = 9
item3  =  6               item3 = 2
item4  =  2               item4 = 5
item5  =  4               item5 = 4
item6  =  7               item6 = 7

6 was the chosen pile by the user. The bottom script would loop until 6 was found. When it is, the var index is set to the position of 6 in the list Pile # List. It then chooses the same position in the # of Stones List and asks the user "how many stones?" It replaces the item index of # Of Stones List with it's value - answer. There might have to be someway to detect if the answer was a number or something.

Script (very sorry, just got back to scratch, I'm not sure how to use Scratch blocks, I will learn soon):

set index to 0
Ask "Choose a pile number"
Repeat until "Index" = "length of Pile # List"
    change Index by 1
        if item(index) = answer
             ask join "How many stones to take out from pile" join Index
             Replace item(Index) of #of Stones with item(index) of #of Stones - answer
             set "index" to length of Pile # List
        end
end

I hope you understand that. BTW, not sure if this will work because the amount of stones in each pile has to be in the same position as each item in the other list. For example: If pile 6 was item 3 of the Pile # List. Then item 3 of the other list should have it's stone amount  smile

Last edited by itsmomito (2012-03-18 02:40:24)

Offline

 

Board footer