1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Random number

Posted by Sisra on Oct 20, 2007

Hi!
I'm very new to NodeBox and programing at all and I know what I'm asking for is a very basic task.
How can I get the random number n

n = random(10, 40)
into the text comand? This doesn't work:
n =random(10, 40)
 
fill(50,50,0,0)
font("Tahoma", 36)
align(CENTER)
text("n", 100, 100, 200)
Thanks in advance


 
Posted by Tom De Smedt on Oct 20, 2007

When you wrap a string of text in quotes it is interpreted literally, i.e. the character n. What you want here is the contents of the variable named n.

So you need to do:

text(n, 100, 100, 200)
When NodeBox executes the text() command it will look up what value is contained in n and draw that to the screen.



Posted by Sisra on Oct 20, 2007

I have tried that too and I'm getting this error in a floating window with buttons to Quit or Continue:
(ValueError: NSInvalidArgumentException - *** -[NSCFNumber length]: selector not recognized)

Here is the hole code:

size(600, 600)
colormode(CMYK, range=100)
 
n = random(10, 40)
 
fill(50,50,0,0)
font("Tahoma", 36)
align(CENTER)
text(n, 100, 100, 200)
I'm using NodeBox 1.0rc7 with Mac OS 10.3.9.
Any clue?



Posted by Tom De Smedt on Oct 20, 2007

Ah OK. The text() command in the 1.0rc7 version doesn't automatically convert numbers to a string, so you need to do this yourself:

text(str(n), 100, 100, 200)



Posted by Sisra on Oct 20, 2007

Now it works!
Thanks.