How to call a function with input from button

Home Forums General Programming How to call a function with input from button

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #117366
    EnzoF04
    Participant
    • Topics: 17
    • Replies: 96
    • Total: 113
    • ★★

    I have a button and a function. I want the function to be modular so I can call this function for different resolution of random numbers. Say a parameter has a resolution of 8 (0-7) or 32 (0-31) I can call the function with ‘randomizeValue(8)’ or ‘randomizeValue(32)’. But how do I get this done from a button? I can call the function ‘randomizeValue’ from the ‘Called when a mouse is down on this component’ menu but I can’t give a value as input for the function.

    Any ideas? Thanks!

    #117384
    human fly
    Participant
    • Topics: 124
    • Replies: 1062
    • Total: 1186
    • ★★★★

    hi,
    you can have a generic random function you call whenever you need it that applies to the min and max of the target parameter. have a look at the D-110 thread and the later panels uploaded towards the end of the thread. the envelopes have a random button, check the method associated with that.

    #117390
    goodweathergoodweather
    Participant
    • Topics: 41
    • Replies: 443
    • Total: 484
    • ★★

    Your issue: “I can call the function ‘randomizeValue’ from the ‘Called when a mouse is down on this component’ menu but I can’t give a value as input for the function

    Some explanations:

    Called when the mouse is down is the equivalent of “On click” event. You get a static view of the component which is in the modulator.
    To reach the value of the modulator, you need to do
    comp:getOwner():getModulatorValue()

    To get a dynamic value changing when you turn a modulator, you should use “Called when the Modulator values changes”. You can then directly use the variable called “value”

    For a randomizer:
    – create a button “Randomize”
    – attach a method to it “Called when the Modulator values changes”
    – in that method, code the things you want to randomize
    – you already have you modulators as variables (mod…)
    – you can get min and max values of them by using mod:getMaxModulatorValue() and mod:getMinModulatorValue()

    #117442
    EnzoF04
    Participant
    • Topics: 17
    • Replies: 96
    • Total: 113
    • ★★

    Thanks for the clarification! This helps! (again)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
There is currently 0 users and 44 guests online
No users are currently active
Forum Statistics
Threads: 2,308, Posts: 16,186, Members: 59,525
Most users ever online was 12 on January 22, 2019 3:47 pm
Do NOT follow this link or you will be banned from the site!