[Closed] Error – Please help
Hi all,
Im pretty new to this and am trying to teach myself some aspects of maxscript from the help files and other scripts
anyway long story short im trying to move an object up to a plane… which works fine with this script (straight out of the help files pretty much)
(
fn g_filter o = superclassof o == Geometryclass
fn find_intersection z_node node_to_z =
(
local testRay = ray node_to_z.pos [0,0,-1]
local nodeMaxZ = z_node.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
intersectRay z_node testRay
)
on isEnabled return selection.count > 0
on Execute do
(
target_mesh = pickObject message:"Pick Target Surface:" filter:g_filter
if isValidNode target_mesh then
(
undo "MoveToSurface" on
(
for i in selection do
(
int_point = find_intersection target_mesh i
if int_point != undefined then i.pos = int_point.pos
)
)
)
)
)
this works perfectly fine, but when i try to apply that bit of script to a button :
clearlistener()
rollout unnamedRollout "Untitled" width:162 height:300
(
button btn8 "Button" pos:[16,137] width:119 height:21
)
on btn8 pressed do
(
fn g_filter o = superclassof o == Geometryclass
fn find_intersection z_node node_to_z =
(
local testRay = ray node_to_z.pos [0,0,-1]
local nodeMaxZ = z_node.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
intersectRay z_node testRay
)
on isEnabled return selection.count > 0
on Execute do
(
target_mesh = pickObject message:"Pick Target Surface:" filter:g_filter
if isValidNode target_mesh
then
(
undo "MoveToSurface" on
(
for i in selection do
(
int_point = find_intersection target_mesh i
if int_point != undefined
then i.pos = int_point.pos
)
)
)
)
)
-------------------------------------------------------------------------------------------------------------
if random_extrude_floater != undefined then (closerolloutfloater random_extrude_floater)
random_extrude_floater = newrolloutfloater "Blah" 180 250
addrollout unnamedRollout random_extrude_floater
I get an error that says
OK
Rollout:unnamedRollout
[size=1]-- Type error: Call needs function or class, got: true
-- Syntax error: at if, expected while
-- In line: if random_extrude_floater != undefined then (closerolloutfloater random_extrude_floater)
[/size]
and I cant seem to work out what the problem is… any help would be greatly appreciated!
place your code between the brackets of “rollout ()”
Something like that:
rollout myScriptRoll "my script"
(
global nomprg="my script"
group "group"
(
button execute "Execute"
)--group
fn myFonction =
(
messageBox("run : "+nomprg)
)--fn
on execute pressed do
(
myFonction()
)--on
)--rollout
if floaterTools != undefined do ( closerolloutfloater floaterTools )
floaterTools = newRolloutFloater "my script" 168 128
addRollout myScriptRoll floaterTools rolledUp:false
good luck
Thanks, youve started to put me in the right direction but im still having a few problems. I tried making a few changes, and the script runs … but i get an error when i click the button. Ive tried any possable logical solution in my limited knowledge but havent had much luck.
rollout myScriptRoll "my script"
(
global nomprg="my script"
fn g_filter o = superclassof o == Geometryclass
fn find_intersection z_node node_to_z =
(
local testRay = ray node_to_z.pos [0,0,-1]
local nodeMaxZ = z_node.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
intersectRay z_node testRay
)
group "group"
(
button execute "Execute"
)--group
on execute pressed do
(
(
print "hello"
on isEnabled return selection.count > 0
(
target_mesh = pickObject message:"Pick Target Surface:" filter:g_filter
if isValidNode target_mesh then
(
undo "MoveToSurface" on
(
for i in selection do
(
int_point = find_intersection target_mesh i
if int_point != undefined then i.pos = int_point.pos
)
)
)
)
)
)--on
)--rollout
if floaterTools != undefined do ( closerolloutfloater floaterTools )
floaterTools = newRolloutFloater "my script" 168 128
addRollout myScriptRoll floaterTools rolledUp:false
i cud see from the script that you used “execute” as a button handler… the word “execute” is a reserved word in maxscript, so i guess u cannot use it for a button handler… try using a different name.
hope this helps!
I’m sorry for this error hiphopclown…
Thanks galagast
The right code is:
rollout myScriptRoll "my script"
(
global nomprg="my script"
group "group"
(
button btn1 "Execute"
)--group
fn myFonction =
(
messageBox("run : "+nomprg)
)--fn
on btn1 pressed do
(
myFonction()
)--on
)--rollout
if floaterTools != undefined do ( closerolloutfloater floaterTools )
floaterTools = newRolloutFloater "my script" 174 128
addRollout myScriptRoll floaterTools rolledUp:false