Home Technical Talk

Set Material Slot to Button based on edit text box

polycounter lvl 13
Offline / Send Message
BradleyWascher polycounter lvl 13
So I was able to assign a material slot to a selected mesh by a simple button press but now I want to be able to define the material slot number in the edit text field then be able to press the button and that material slot would be used.

I just cant seem to figure out how to mesh the information from the text box to the button click. Here is what i have so far



on btn4 pressed do

(selection.material = meditmaterials[1])



and my edit text box is called "edt4" can anyone tell me what I should write to make it so the number in my edit text box is used in place of the default map slot 1 right now?

I was experimenting with <edt4>.text but didnt know if that was the right direction or where to implement it. ( This is my first time diving in to max script in any fashion lol so please mind my complete lack of knowledge lol)

Problem.jpg

Replies

  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Using edit text boxes is a bad idea. they are for string values and you will need to cast them to integers(convert them) to use their values. the thing is you can input what you want into an edit text field and its not allways going to be castable to an int.

    so say your text is '100'
    x = "100" as integer
    returns: 100

    now say you slip up and add some text to the field, in this case a space
    x="100 " as integer
    returns: undefined

    your script will now crash.



    Use a spinner instead, and explicitly set it to integer.

    spinner spn_myMatID "Material Assign" range:[1,100,1] type:#integer


    then you say
    selection.material = meditmaterials[spn_myMatID.value]

    or even better
    on spn_myMatID changed arg do
    (
    selection.material = meditMaterials[arg]
    )
    in this case the event looks for a variable, in this case 'arg' it uses this to store the current value of the spinner. its just a handy shortcut, arg can be any valid variable name
  • BradleyWascher
    Options
    Offline / Send Message
    BradleyWascher polycounter lvl 13
    hey, thanks a lot, originally I had spinners in there but in my lack of knowledge I started to tell myself "hey text boxes should be simpler with not having to account for the up and down arrows in code :). Guess I was wrong lol. Thanks for the help once again
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    no worries. happy coding
Sign In or Register to comment.