Home   Archive   Permalink



I'm a noob, please help

There is a 15 piece slider puzzle example on the Learn Rebol page (this guide is great, thanks for creating it!). I thought it would be neat to enhance the program to randomize the tiles. I added some code but I get "misplaced" errors like so;
    
Misplaced item: []
Unknown word or style: loop
Misplaced item: 15
Misplaced item: [mynum: random 15
     result: find pieceblock
]
    
Here's my code below, where should the misplaced code be placed? Thanks very much in advance for any help.
    
R E B O L [title "tile game"]
    
view center-face layout
[
    origin 0x0 space 0x0 across
    style piece button 60x60
    [
    if not find [0x60 60x0 0x-60 -60x0] (face/offset - empty/offset) [exit]
    
    temp: face/offset
    face/offset: empty/offset
    empty/offset: temp
    
    ]
         ;THIS IS THE STUFF I ADDED BELOW
    pieceblock: []    
    loop 15 [ mynum: random 15
    result: find pieceblock mynum
    if result == "" [ append pieceblock mynum ]         
        ]    
    
    piece (pieceblock 1) piece (pieceblock 2) piece (pieceblock 3) piece (pieceblock 4) return
    piece (pieceblock 5) piece (pieceblock 6) piece (pieceblock 7) piece (pieceblock 8) return
    piece (pieceblock 9) piece (pieceblock 10) piece (pieceblock 11) piece (pieceblock 12) return
    piece (pieceblock 13) piece (pieceblock 14) piece (pieceblock 15)
; MY CODE ABOVE
    
    empty: piece 200.200.200 edge [size: 0]
]

posted by:   Steve       8-Sep-2010/19:40:51-7:00



You are writing REBOL code inside the layout block. The layout block is written in the VID dialect, and a dialect is a sublanguage, which doesn't necessarily use the same words and syntax as what normally write. It only works inside that block. That's why you get:
    
Misplaced item: []
Unknown word or style: loop
etc.
because that is interpreted incorrectly by the LAYOUT function.
    
Write the PIECEBLOCK generator code before VIEW statement at the top.
    
The references in the layout code, which you wrote correctly needs a / added, i.e.
    
pieceblock/1, pieceblock/2, etc. It should not be necessary to wrap them in (), but I'm not entirely sure.
    
Hope that helps a bit.

posted by:   Henrik       9-Sep-2010/2:38:57-7:00



You can generate the random list more easily:
    
R E B O L [title "tile game"]
pieceblock: random ["1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"]
view center-face layout [
     origin 0x0 space 0x0 across
     style piece button 60x60 [
         if not find [0x60 60x0 0x-60 -60x0] (face/offset - empty/offset) [exit]
         temp: face/offset
         face/offset: empty/offset
         empty/offset: temp
     ]    
     piece (pieceblock/1) piece (pieceblock/2) piece (pieceblock/3) piece (pieceblock/4) return
     piece (pieceblock/5) piece (pieceblock/6) piece (pieceblock/7) piece (pieceblock/8) return
     piece (pieceblock/9) piece (pieceblock/10) piece (pieceblock/11) piece (pieceblock/12) return
     piece (pieceblock/13) piece (pieceblock/14) piece (pieceblock/15)
     empty: piece 200.200.200 edge [size: 0]
]

posted by:   Nick       9-Sep-2010/6:34:48-7:00



Here's how to create the initial list using a loop - and don't forget to use random/seed to get random numbers:
    
R E B O L [title "tile game"]
random/seed now/time
pieceblock: copy []
repeat x 15 [append pieceblock form x]
pieceblock: random pieceblock
view center-face layout [
     origin 0x0 space 0x0 across
     style piece button 60x60 [
         if not find [0x60 60x0 0x-60 -60x0] (face/offset - empty/offset) [exit]
         temp: face/offset
         face/offset: empty/offset
         empty/offset: temp
     ]    
     piece (pieceblock/1) piece (pieceblock/2) piece (pieceblock/3) piece (pieceblock/4) return
     piece (pieceblock/5) piece (pieceblock/6) piece (pieceblock/7) piece (pieceblock/8) return
     piece (pieceblock/9) piece (pieceblock/10) piece (pieceblock/11) piece (pieceblock/12) return
     piece (pieceblock/13) piece (pieceblock/14) piece (pieceblock/15)
     empty: piece 200.200.200 edge [size: 0]
]

posted by:   Nick       9-Sep-2010/6:39:06-7:00



Thanks to both of you, Henrik for the explanation and Nick for the code examples. I really appreciate it. I am trying the loop version now and it's working great, does exactly what I want.

posted by:   Steve       9-Sep-2010/18:16:21-7:00