Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to clear a certain parameter

edited October 2014 in General Posts: 31

I want an integer slider for difficulty, and in the callback function I use parameter.clear(), because in one difficulty level, there are extra parameters. However, this clears all parameters, including the difficulty slider. I was hoping there was a way to clear only a few certain parameters.

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    Nope. The easiest may be to put the creation of parameters into functions, one for each different set, and clear them and run the appropriate function, when the difficulty changes.

  • dave1707dave1707 Mod
    edited October 2014 Posts: 7,907

    Removed comment. Miss read the question.

  • edited October 2014 Posts: 1,976

    Comment removed

  • dave1707dave1707 Mod
    edited October 2014 Posts: 7,907

    @SkyTheCoder Apparently I mis-read the question. After reading it again, I guess he wants to remove a parameter, not reset it to a certain value. I'm watching football, so my mind isn't fully on the forum.

  • Posts: 2,042

    I thought you could do slider = parameter.integer() parameter.remove(slider) Guess I was wrong. Would be a nice feature

  • edited October 2014 Posts: 31

    I've got this:

    function changeDifficulty(v)
        if v == 1 then
            parameter.clear()
            parameter.integer("Diffuculty", 1, 3, v, changeDifficulty)
        end
        if v == 2 then
            parameter.clear()
            parameter.integer("Diffuculty", 1, 3, v, changeDifficulty)
            parameter.text("X", 0, changeX)
            parameter.text("Y", 0, changeY)
        end
        if v == 3 then
            parameter.clear()
            parameter.integer("Diffuculty", 1, 3,  v, changeDifficulty)
        end
    end
    

    so far, where the parameter.integer is the difficulty slider and the function is changeDifficulty, the callback for the slider. This gives me a stack overflow, though.

  • IgnatzIgnatz Mod
    edited October 2014 Posts: 5,396

    @LaserGate_coder -There's a gotcha with callback functions in parameters, that when you declare the parameter, the callback gets called. This is causing an infinite loop.

    If you wrap the callback in a function, it avoids the problem, so try this

    parameter.integer("Diffuculty", 1, 2, v, function() changeDifficulty() end)
    
Sign In or Register to comment.