Notifications
Clear all

[Closed] Error in code

I wrote a struct to create moon objects ( which are regular and irregular), so when the irregular variable is set to true the if statement is executed and it some noise modifier is added to give the moon the irregular shape. But although I monitored the max listener’s commands and did he same as maxscript, it is giving me an error:

This is the struct.

struct moonObject
(

mname, mradius, map, rotSpeed, revolSpeed, axiTilt, irregular, ix, iy, iz, iseed, iscale, gx, gy, gz, shape, pathOfMoon, pathController,

fn drawMoon =

(

– draw shape of moon

shape = Sphere radius: mradius smooth:on segs:100 chop:0 slice:off sliceFrom:0 sliceTo:0 mapcoords:on recenter:off pos:[0,0,0] isSelected:on

– name the moon

shape.name = mname

if( irregular == true ) then

(

modPanel.addModToSelection (Noisemodifier ()) ui:on

mname.modifiers[#Noise].seed = iseed

mname.name.modifiers[#Noise].scale = iscale

mname.modifiers[#Noise].strength = [ix,iy,iz]

modPanel.setCurrentObject $mname.modifiers[#Noise]

$mname.modifiers[#Noise].gizmo.pos += [gx,gy,gz]

)

– assign moon material

meditMaterials[1].diffuseMap = Bitmaptexture fileName: map

shape.material = meditMaterials[1]

showTextureMap meditMaterials[1] on

– define moon rotation

rot_moon = eulerangles axiTilt 0 0

rotate shape rot_moon

)

and this is the error:

[size=1]– Error occurred in drawMoon();

– Unknown property: “modifiers”

[color=white]thank you all…

[/color][/size]

6 Replies

thats weird i copy paste your code and got this error instead

– Syntax error: at end, expected )
– In line:

BTW you we’re missing on closing bracket i dont think that was the cause of the error but that what i found for now

see with a close bracket at the end it return the struc. data

#Struct:moonObject(
axiTilt:<data>,
iz:<data>,
gy:<data>,
map:<data>,
revolSpeed:<data>,
iy:<data>,
drawMoon:<fn>,
gx:<data>,
shape:<data>,
rotSpeed:<data>,
ix:<data>,
pathController:<data>,
mradius:<data>,
iscale:<data>,
irregular:<data>,
pathOfMoon:<data>,
mname:<data>,
iseed:<data>,
gz:<data>)

Hello,

You can't really use a string variable to reference the object in this way:

      mname = "some object"
      mname.modifiers[#Noise].seed = iseed
      

You need to reference it by the actual node. To fix it, you can change it to look like this… this should work, since you know the object is selected (you used isSelected:on):


      $.modifiers[#Noise].seed = iseed
      
Alternatively, you could use "shape.modifiers" instead of "mname.modifiers", since the shape variable refers to the actual node.
  
  Here's a working version:

       struct moonObject
       (
       	mname, mradius, map, rotSpeed, revolSpeed, axiTilt, irregular, ix, iy, iz, iseed, iscale, gx, gy, gz, shape, pathOfMoon, pathController,
       
       	fn drawMoon =
       	(
       		-- draw shape of moon
       		shape = Sphere radius: mradius smooth:on segs:100 chop:0 slice:off sliceFrom:0 sliceTo:0 mapcoords:on recenter:off pos:[0,0,0] isSelected:on
       		
       		-- name the moon
       		shape.name = mname
       		
       		if( irregular == true ) then
       		(
       			modPanel.addModToSelection (Noisemodifier ()) ui:on
       			$.modifiers[#Noise].seed = iseed
       			$.modifiers[#Noise].scale = iscale
       			$.modifiers[#Noise].strength = [ix,iy,iz]
       			modPanel.setCurrentObject $.modifiers[#Noise]
       			$.modifiers[#Noise].gizmo.pos += [gx,gy,gz]
       		)
       		
       		-- assign moon material
       		meditMaterials[1].diffuseMap = Bitmaptexture fileName: map
       		shape.material = meditMaterials[1]
       		showTextureMap meditMaterials[1] on
       		rot_moon = eulerangles axiTilt 0 0
       		rotate shape rot_moon
       	)
       )
       
       moonInst = moonObject mname:"sjkdfdlsf" mradius:5 map:"kljasdfjl" axiTilt:(4.4 as float) irregular:true iscale:1 ix:4 iy:4 iz:4 gx:6 gy:8 gz:9 iseed:5
       moonInst.drawMoon()
       

yes it worked! :bounce:

thank you guys…

hi again…

Im having another stupid error, remember ajohnson when you told me about the loadMaxFile command, so I used it but it isnt loading the file it even returns false! here is what I wrote

filename = getdir #scripts + “\Earth.max”

loadMaxFile filename quiet: true

Earth.max is a file that I created earlier and saved it in scripts file in the 3dmax directory…

everything is ok when I save the file Earth.max using the same filename, but here it is returning false, help! I read the docs but nothing helped ::sad:

don’t forget to escape backslashes:


 filename = getdir #scripts + "\\Earth.max"
 

Also, type the command above into the listener, which should output the path to the file… double (and triple :)) check that the file actually exists.

i found out what caused my error and I am not PROUD to say it, I created my error in the script that created the file im trying to open and i was saving it with out escaping the \ because i created a new way to not let \ reiun my work! i did this “\ “, so i should have called

filename = getdir #scripts + “\ Earth.max” or something but anyways i fixed the script that caused the error, thanx ajohnson

i was wondering if we can create folders using maxscript, it is either there is nothing in the docs or im not using it right!

Thanx again