Parameter

Helpp… My print wont update when i change my score with the parameter!
Here is my code.

function setup()
    score=30
    if score<=10 then
        print("fail!")
    elseif score <=20 then
        print("better")
    elseif score <=30 then
        print("good")
    end
    scorecontrol()
end

function draw()
    
end

function scorecontrol()
    parameter.integer("score",0,50,0)
end

It is changing you just don’t come to know cause those conditions are in the setup. put them in draw and it’ll work. Since draw is called every frame while setup is only called once. And be careful if you put it in draw it’ll continuously print the strings. If you want to print it only once then add a callback the parameter. Like so

function setup()
    score = 30
    scorecontrol()
end

function draw()

end

function scorecontrol()
    parameter.integer("score",0,50,0,checkScore)
end

function checkScore()
    output.clear()
    if score<=10 then
        print("fail!")
    elseif score <=20 then
        print("better")
    elseif score <=30 then
        print("good")
    else
        print("outstanding")
    end
end

@Saurabh thanks i will check it out.

@Saurabh on more question… Can you explain what an callback is?

A callback is simply a function that is called when something happens. So in the above example, when the value score is changed, the function checkScore() is called.

From the web: “In computer programming, a callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time. The invocation may be immediate as in a synchronous callback or it might happen at later time, as in an asynchronous callback”

In @Saurabh 's example, parameter.integer("score", 0, 50, 0, checkScore)
checkScore is the callback function that will be called by parameter.integer() when its value has changed. Thus, making this an asynchronous callback.

@JakAttak @matthew thanks for explaining!