PDA

View Full Version : undefined variable problem


rafoarc
07-12-2009, 09:26 PM
hello everyone,
I have a small problem when i try to run the following piece of code:

for j in 1 to nGen do
(
for i in 1 to nCells do
(
if (cellAuto[j][i] == 1) then
p = plane()
p.length = 1
p.width = 1
p.pos.x = i
p.pos.y = -j
)
)

I get "Unknown property: "length" in Plane". And when I change it to this :

...
p = plane length:1 width:1
move p [i,-j,0]
...

i get "No ""move"" function for undefined". Actually, i does work sometimes (?) when I run pieces of my code separately, but it doesn't work at all when i wrap it in a button. I assume that for some reason it considers p as an undefined variable... but i am not really sure...

thanks

MarcoBrunetta
07-12-2009, 11:42 PM
I think the problem is that it should be written like:

for j in 1 to nGen do
(
for i in 1 to nCells do
(
if (cellAuto[j][i] == 1) then
(
p = plane()
p.length = 1
p.width = 1
p.pos.x = i
p.pos.y = -j
)
)
)

Without the set of parenthesis I added, the program will only consider the first like ("p = plane()") to be part of the THEN statement. Thus in some cases the script is not creating the plane since cellAuto[j][i] is different than 1 but it's still trying to set the plane's properties.

rafoarc
07-13-2009, 05:47 AM
Yes, you are right... it works this way... Thanks!

CGTalk Moderation
07-13-2009, 05:47 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.