PDA

View Full Version : ERROR .. where is the problem


mahaelgewely
09-16-2008, 11:33 PM
Hello guys,

I have a problem in my MaxScript code and i want you to help me revising it.
The function is working well when i execute it separately but when i involve it within a rollout, i get this error message.

>> MAXScript Rollout Handler Exception: -- Argument count error: classOf wanted 1, got 2 <<

here is the code


rollout r1 "Candilis Cellular Automata" width:730 height:319
(

GroupBox grp1 "RESIDENTIAL BUILDINGS GAME OF LIFE " pos:[10,10] width:230 height:300

GroupBox grp10 "Site restrictions" pos:[25,30] width:200 height:77
spinner spn7 "X- Dimension" pos:[85,50] width:123 height:16
spinner spn9 "Y- Dimension" pos:[85,79] width:123 height:16 range:[0,100,0]

GroupBox grp33 "Building restrictions " pos:[25,112] width:200 height:79

spinner spn10 "No of Stories " pos:[83,134] width:125 height:16 range:[0,100,0]
spinner spn33 "Court Diameter" pos:[81,160] width:127 height:16 range:[0,100,0]



GroupBox grp45 "Generate Alternatives " pos:[25,195] width:200 height:106
radiobuttons rdo11 "No of Prototypes" pos:[44,218] width:166 height:30 labels:#("1", "2*2", "4*4", "6*6") columns:4
button btn1 "Generate" pos:[61,256] width:127 height:37


GroupBox grp3 "COMBINATIONS" pos:[250,10] width:230 height:300

dropdownList ddl3 "Interpolation Direction" pos:[264,43] width:205 height:40 items:#("Vertical", "Horizontal")
GroupBox grp11 "Vertical " pos:[265,94] width:200 height:94
radiobuttons rdo7 "Organisation" pos:[289,107] width:166 height:30 labels:#("Staggered", "Random") columns:2
spinner spn18 "No. of Stories" pos:[330,149] width:123 height:16 enabled:true range:[0,4,0] type:#integer

GroupBox grp12 "Horizontal" pos:[265,195] width:200 height:102

radiobuttons rdo6 "Organisation" pos:[301,215] width:128 height:46 labels:#("Ribbon", "Puzzle", "Patio", "Grouped") default:1 columns:2
spinner spn19 "No. of Stories" pos:[330,270] width:123 height:16 enabled:true range:[0,4,0] type:#integer



GroupBox grp2 "SITE RESTRICTIONS" pos:[490,10] width:230 height:177

spinner spn6 "X- Dimension" pos:[581,49] width:123 height:16 enabled:true range:[0,4,0] type:#integer
spinner spn34 "Y- Dimension" pos:[581,79] width:123 height:16 enabled:true range:[0,4,0] type:#integer
pickbutton btn20 "Generate" pos:[543,123] width:130 height:40


GroupBox grp63 "ABOUT" pos:[490,195] width:230 height:115

label lbl2 "This rollout resembles George Candilis' rules for residential buildings using Cellular Automata technique" pos:[498,212] width:217 height:43
label lbl1 "By:" pos:[596,255] width:30 height:14 enabled:true
label lbl4 " MAHA EL GEWELY " pos:[557,271] width:104 height:17 enabled:true
label lbl3 "maha_elgewely@alex.edu.eg" pos:[539,287] width:146 height:17 enabled:true




-- variables: Xmax Ymax NoGen CourtDia Alternatives

------------------------------------------ function starts here ---------------------------------------------------------

fn FormGeneration A B C D E =
(

for h= 1 to E
do(

-- creating first generation grid
for x= 0 to A do for y= 0 to B do (
MyPlane= Box length:1 width:1 Height:1 lengthsegs:1 widthsegs:1
MyPlane.name= "Cell_" + x as string + "_X_" + y as string + "_X_0.0"
MyPlane.pos = [x,y,0]
MyPlane.wirecolor= [190,200,170]

hide( for o in geometry where distance o.center [10,10,0] > (D+3) and distance o.center [10,10,5]< B collect o)
hide( for o in geometry where distance o.center [10,10,0] < D collect o)
)
-- for o in geometry where try(o.ishidden== false) catch (false) do
for o in geometry where try(o.ishidden== false) catch (false) do(

state= random 0 1
if (state == 0) then hide o
)

for gen=0.0 to C by 1.0 do
(
-- first pass: neighbors information

StateArray = #() -- array to save each cell neighboring status
lifeORdead= #() -- array to save each cell status
Idx=1 -- initialize a conter for StateArray Index
for x=1 to (A-1) do for y=1 to (B-1) do
(
-- defining each cell to collect it's neighbor visibility
NameOfCell= "Cell_" + x as string + "_X_" + y as string + "_X_" + gen as string

visible= 0 -- number of visible cell's neighbors

for i= -1 to 1 do for j= -1 to 1 do
(
if (i==0 and j==0) then (

LifeorDeadCell= execute (" $"+ NameOfCell + ".ishidden" )
if (LifeorDeadCell == false) then ( lifeORdead[Idx]= 1)
else (lifeORdead[Idx]= 0)
)


else(
-- defining cell NeighborName
NeighborName= "Cell_" + (x+i) as string + "_X_" + (y+j) as string + "_X_"+ gen as string
checkclass= execute("classof $" + NeighborName + "== Box")
if try (checkclass) catch (false) do
(

Visibility= execute (" $"+ NeighborName + ".ishidden" ) -- check cell neighbor visibility

if (visibility == false) then (visible= visible+1) -- update number of visible neighbors
else (visible=visible)
)
)

)

StateArray[Idx]= visible -- placement of visible cells no in the cell index of the StateArray
Idx=Idx+1 -- move to the next cell
)



-- second pass: applying rules

Idx=1 -- initialize variable to loop betwenn cells
for x=1 to (A-1) do for y=1 to (B-1) do
(
TotoPlane= box length:1 width:1 Height:1 lengthsegs:1 widthsegs:1
TotoPlane.name= "Cell_" + x as string + "_X_" + y as string + "_X_"+ (gen+1) as string
TotoPlane.pos = [x,y,((gen+1)+(0.2*(gen+1)))]
TotoPlane.wirecolor= [190,200,170]

--Conway's Game of Life:
--1. Any live cell with fewer than two live neighbors dies, as if by loneliness.
--2. Any live cell with more than three live neighbors dies, as if by overcrowding.
--3. Any live cell with two or three live neighbors lives, unchanged, to the next generation.
--4. Any dead cell with exactly three live neighbors comes to life.

-- if live cell



Visibility01= " $"+ TotoPlane.name + ".ishidden"+ " = true"
Visibility02= " $"+ TotoPlane.name + ".ishidden"+ " = false"
if (lifeORdead[Idx]==1) then (


case of
(
(StateArray[Idx]<2): execute Visibility01
(StateArray[Idx]>3): execute Visibility01
(StateArray[Idx]==2): execute Visibility02

(StateArray[Idx]==3): execute Visibility02
)
)

else (
case of
(

(StateArray[Idx]==3): execute Visibility02

(StateArray[Idx]!=3): execute Visibility01
)

)
Idx=Idx+1 -- move to the next cell

)
redrawViews()

)


-- for o in objects where try (o.ishidden == true) catch (false) do delete o

group(for o in objects where distance o.center [10,10,6] < A collect o)
move (for o in objects where distance o.center [10,10,6] < A collect o) [50,(10*h),0]
freeze(for o in objects where distance o.center [10,10,6] >A collect o)
)

)
------------------------------------------- function ends here -------------------------------------------------------------




on btn1 pressed do
(
print spn7.value
print spn9.value
print spn10.value
print spn33.value
print rdo11.state

yarab= FormGeneration spn7.value spn9.value spn10.value spn33.value rdo11.state
)

)createdialog r1

Kramsurfer
09-18-2008, 01:03 AM
Off the top of my head... always use parentheses around string additions...

NeighborName = ( "Cell_" + (x+i) as string + "_X_" + (y+j) as string + "_X_"+ gen as string )

RobGalanakis
09-18-2008, 01:08 AM
NeighborName= "Cell_" + (x+i) as string + "_X_" + (y+j) as string + "_X_"+ gen as string
checkclass= execute("classof $" + NeighborName + "== Box")

Change that to:
NeighborName= "Cell_" + (x+i) as string + "_X_" + (y+j) as string + "_X_"+ gen as string
tempStr = ("classof $" + NeighborName + "== Box")
print tempStr
execute tempStr

Check what tempStr is, I am sure there is a space in the "NeighborName" variable somewhere. So you are doing "classOf $startOfObjName endOfObjName == Box" instead of "classOf $startOfObjNameEndOfObjName == Box". That errant space makes it look like you are supplying 'classOf' with two arguments (the object with an incorrect/abbreviated name, and a undefined variable) instead of one (the object).

Also, look at "getNodeByName" instead of using execute.

Zbuffer
09-18-2008, 01:51 AM
Hi,

The naming you use is bad beacause is uses points.
use single quotes around the name string: $'my.weird name'


checkclass= execute("classof $'" + NeighborName + "'== Box")
Visibility= execute ("$'"+ NeighborName + "'.ishidden")
Visibility01 = "$'"+ TotoPlane.name + "'.ishidden"+ " = true"
Visibility02 = "$'"+ TotoPlane.name + "'.ishidden"+ " = false"

RobGalanakis
09-18-2008, 03:45 AM
Hi,

The naming you use is bad beacause is uses points.
use single quotes around the name string: $'my.weird name'


checkclass= execute("classof $'" + NeighborName + "'== Box")
Visibility= execute ("$'"+ NeighborName + "'.ishidden")
Visibility01 = "$'"+ TotoPlane.name + "'.ishidden"+ " = true"
Visibility02 = "$'"+ TotoPlane.name + "'.ishidden"+ " = false"


Names will also break with '-' I think (at least the syntax highlighting breaks with a hyphen).

It is always wise to surround names with single quotes when using an unknown name. Should have caught that.

Kramsurfer
09-18-2008, 06:21 AM
we use "-" in names all the time... In our naming conventions, we just it to delineate all sorts of stuff...
ex. CAR-BMW_320i-BLACK

"-" 's are fine... :-)

Totally.missed.the.points.too.....

mahaelgewely
09-19-2008, 10:10 PM
i am thankful for you for your advice and help. because i study maxscript as a self study subject and i have no one to support me .
thank u all .. the function is working now!

RustyKnight
09-22-2008, 02:07 AM
i have no one to support me .

Now you do :)

CGTalk Moderation
09-22-2008, 02:07 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.