Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Beginner's bug
Pages: [1] Print
Author Topic: Beginner's bug  (Read 215 times)
alain91
Newbie
*
Offline Offline

Posts: 2


View Profile
Beginner's bug
« on: September 18, 2008, 08:15:40 AM »

Bonjour,
I'am beginner in REBOL and I have to modify a game script

original script is :

rebol []

view center-face layout [
   origin 0x0 space 0x0 across
   style p 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
   ]

   p "E" p "G" p "A" p "O" return
   p "B" p "F" p "D" p "K" return
   p "C" p "H" p "I" p "L" return
   p "N" p "M" p "J"

   empty: p 200.200.200 edge [size: 0]
]

I wanted to do a loop with letters. Like that :
rebol []

lettres: ["A" "B" "C" ... "O"]
view center-face layout [
   origin 0x0 space 0x0 across
   style p 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
   ]

   foreach lettre lettres [p lettre]

   empty: p 200.200.200 edge [size: 0]
]

An error is raised : p has no value
near p lettre

Where is the tip ?
Logged
Brock
Newbie
*
Offline Offline

Posts: 14


View Profile
Re: Beginner's bug
« Reply #1 on: September 18, 2008, 10:57:09 PM »

There are some tricks to building this LAYOUT as what you are trying to do is dynamically build it.  I found a link that explained how to build dynamic LAYOUTS and was able to build this little script....
Code:
Rebol[
title: "Dynamic Matrix of Buttons"
author: "Brock Kalef"
]

matrix: copy [
    space 0x0
    style ntg toggle green red 24x18 font [size: 9 colors: pewter shadow: 0x0]
    across
]

counter: 1
cols: rows: 5
row-cnt: :rows
col-cnt: :cols
while [row-cnt <> 0] [
    while [col-cnt <> 0] [
       
        temp: to set-word! rejoin ["cell" counter] ; creates variable
        temp2: to-word rejoin ["cell" counter]
        temp3: to path! compose [(temp2) state]
        append matrix temp
        append matrix 'ntg
        append matrix to string! counter
        append/only matrix compose [print (temp3)]
        counter: counter + 1
        col-cnt: col-cnt - 1
    ]

    append matrix compose [return]  ; reset column location at next row

    col-cnt: cols      ; reset max column count
    row-cnt: row-cnt - 1   ; decrease row count
]
lay-display: layout matrix

;cell8/state: true ;works - must be after layout is made
;show cell8 ;works

view lay-display

You will notice the word  MATRIX  is defined first, this is the word that I am assigning all of the LAYOUT to.

I then loop through the creation of rows and columns of buttons (actually toggles, but they are essentially the same thing).  Here I append items to the word 'matrix, which again is the word we are storing the building blocks of the layout in.

I then use...
Code:
lay-display: layout matrix
to actually create the LAYOUT and...
Code:
view lay-display
to view the layout.

There is some fancy stuff in the loop to define my toggle (button) names dynamically and the path values to be able to change the state of the toggles, but it's a bit tricky and I don't think I'd do it justice in explaining.

I know this is one way of doing it, but not sure if there is a better way.  I hope this helps.

Brock
Logged
alain91
Newbie
*
Offline Offline

Posts: 2


View Profile
Re: Beginner's bug
« Reply #2 on: September 19, 2008, 07:31:35 AM »

Thank's very much

That is exactly the way of thinking I was searching. This code help me to make the difference between REBOl code an VID dialect and How it is possible de merge those together in a script.

Bye.
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Beginner's bug
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2008, 07:00:26 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2314 Posts in 596 Topics by 4200 Members
Latest Member: Takunretarhut

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc