Notifications
Clear all

[Closed] Beginner help with Maxscript

Hi, I am currently studying a design course that includes a Maxscript unit. So far things are just not “clicking” which is slowing my learning. This problem is confounded by the fact that my lecturer has very poor English and even when he explains things in great detail, it leaves many of his students befuddled. I am really hoping someone will be kind enough to spare some time here to help me out here.

Anyway, here is my specific problem:

Initially I had to write a script that uses a ‘for’ loop to create 100 boxes at random positions. I did this (as you will see below).

I then have to create a rollout with a button that when pressed, executes the above mentioned ‘for’ loop. I Did that.

I then need to add a spinner that would allow the user to set how many random boxes are generated when the button is pressed. This is where I am having issues. I cannot work out how to link the spinner to the button to achieve the desired result. If someone could help with this then that would be great.

After I have the spinner working I need to do the following: Add a ‘dice roll’ stopping condition, using a 20 sided dice. So the script stops looping if a 20 is rolled. There is a second stopping condition too, and that is if the number of boxes specified by the the user have been created then the script needs to stop. If neither of these conditions are true then the script will keep looping until a condition is met. I have no idea how to go about this so any help would be much appreciated.

Here is what I have written so far:


resetMaxFile #noprompt --resets the scence without a prompt
try (destroydialog myrollout) catch ()


rollout myrollout "testing" width:350 height:713
(

	button but_01 "Random Boxes" pos:[37,7] width:88 height:21
	spinner spn-01 "Box Qty" pos:[136,8] width:46 height:16 range:[0,100,50]
	
	on but_01 pressed do
	(mybox = box length:10 width:10 height:10 wirecolor:blue --new box
			for i = 1 to 100 do --repeat 100 times, for each iteration
			(
				box_copy = copy mybox --create a copy of the original box
				box_copy.pos  = random [-20, -20, 0] [80, 80, 0]) --place a random position within the defined coords
			)
)


createdialog myrollout 200 200


Thanks very much.

2 Replies

You were very close making the spinner work.

 Currently i only have time to get that working. when i get some spare time during the day ill take a look at the rest.
 
 Highlighted in red is what i changed.

   
   rollout myrollout "testing" width:350 height:713
   (
   
   	button but_01 "Random Boxes" pos:[37,7] width:88 height:21
   	spinner spn_01 "Box Qty" pos:[136,8] width:46 height:16 range:[0,100,50] [color=Red]type:#integer[/color]
   	
   	on but_01 pressed do
   	(
   		if spn_01.value != 0 then
   		(
   			mybox = box length:10 width:10 height:10 wirecolor:blue --new box
   			for i = 1 to spn_01.value-1 do --repeat 100 times, for each iteration
   			(
   				box_copy = copy mybox --create a copy of the original box
   				box_copy.pos  = random [-20, -20, 0] [80, 80, 0]
   			) --place a random position within the defined coords
   		)else(
   			messagebox "Spinner value equals 0"
   		)
   	)
   )
   createdialog myrollout 200 200
   

Thankyou ever so much! I cannot believe I did not try putting the spinner value in the place you put it, I spent hours trying different layouts and it did not occur to me to put it there, which seems stupid in hindsight.

I have now also managed to get my random dice working as intended so no need for you to spend time on that.

I very much appreciate your help