Skip to main content

Syntax Question, how to increase variable?

2 replies [Last post]
riepi
Offline
Joined: 2008-03-27
Points: 0

 </p>
<p>    public function create():Node{<br />
        return Group {<br />
            var ypos = 0; //YPosition Rectangle<br />
            content:[<br />
                for( i in [0..4]){<br />
                    Rectangle {<br />
                        x: 10<br />
                        y: bind ypos<br />
                        width: 140<br />
                        height: 20</p>
<p>                        fill: Color.BLACK<br />
                    }<br />
                    //ypos += 20; How does it work?<br />
                }//for</p>
<p>            ]//content Group</p>
<p>        }</p>
<p>    }</p>
<p>

Where to place "ypos+=20;" or for example an if statement: if( i%2 == 0){ the fill color has to change }

I tried many times, but every time something is wrong. I want to draw some Rectangles to simulate a table.

riepi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

The for-expression in your example is not a for-loop in the conventional sense, but you are defining a sequence of Rectangles. Putting some statements in between will usually not work.

Have you tried "y: 20*i"?

You can set the attributes in an object literal to any expression, so for example something like this should work:
fill: if (i%2 == 0) Color.BLACK else Color.WHITE;

riepi
Offline
Joined: 2008-03-27
Points: 0

thx a lot

now i know a little bit more about the language :)