Notifications
Clear all

[Closed] Checkbox returning to its initial state

Hi guys,

I am trying to learn maxscript and I got this problem while trying some codes…

I’ve made a check button in a custom attribute of an object in the scene with a changed state code, when the button is pressed do … else do… And so far it’s fine. But, when I click on other object in the scene the state of that check button becomes pressed again, it returns to its initial state. Is there any way to hold the state I left after clicking on it?

checkbutton theBTN “Button” width:125 height:30 checked:true

on theBTN changed state do (
if state == on then (code 1)
else (code 2)
)

I’ve noticed the script it’s returning TRUE after executed, I think it might have something to do with my problem, but I don’t know how to solve it. Thank you in advance for your help

6 Replies

What does your CA def look like? Unless you have a paramater there that’s exposed via that checkox, it won’t get automatically stored.

1 Reply
(@xhandy)
Joined: 10 months ago

Posts: 0

I am using the check button to set/remove a look at constraint. When its status is changed from on to off set the look at of an object, the other status changing removes the look at. I am trying to use script to improve a rigg of one character i’m doing as exercise and portfolio.

I even thought about doing two distints buttons instead a check button. But the thing is that I want to prevent the use of the action of add the look at when It is already applied.

You need to add a parameter block to your custom attributes. This is laid out pretty clearly in the maxscript help files.

Right now your CAs are not saving to anything. They perform superficial UI functions once loaded, but aren’t actually putting their data anywhere…so each time their rollout is re-initialized, they reset their values.

1 Reply
(@xhandy)
Joined: 10 months ago

Posts: 0

Sorry for taking so long to answer, and thanks for your reply. I’ve understood what you said but I am not very used to maxscript so I don’t know for sure how to block the parameter. I was able to solve the problem using a different approach, I’ve created two buttons (ON and OFF) and to prevent the use of the action of add the look at when It is already applied I used a IF condition to check the quantity of list elements in the rotation controller. That way if the user clicks the ON button but the look at is already applied the script returns a warning to the user and it stops the rest of the script.

I would appreciate if you could show how to block the parameter, it’s always good to learn something new

Thank you guys.

To store the state, do it like that :

(
	custAttrCA= attributes custAttr
	(
		-- this is the parameter block
		parameters main rollout:params
		(
			-- you have the state parameter link to the checkbutton with "ui:stateBtn "
			state type:#boolean ui:stateBtn default:false
		)

		rollout params "Weapon Parameters"
		(
			checkbutton stateBtn "On / Off"
		)
	)

	custAttributes.add $ custAttrCA
)

Then you can access the parameter like any properties:

$.state

Maxscript help

1 Reply
(@xhandy)
Joined: 10 months ago

Posts: 0

Great

Thank you for the explanation, I will test it out here.