on screen parameter

hi,

is it possigble to make a parameter in the program itself?
and if it possible, does anyone have a code for me?

@jessevanderheide, do you mean something like the integer slider, but on the screen and not the side window?

@JakAttak yes thats what i mean.

It’s possible, but you’d have to write a class that does it.

@JakAttak ooh thats a bum :frowning:

Check out Cider 7. I also saw another UI project around somewhere too, I forget what it’s called though.

@slashin8r there is cider and there’s one by I think Luatee.

@jessevanderheide, here is something I wrote that is essentially a copy of the integer slider:


--# Main
-- IntegerSlider

-- Use this function to perform your initial setup
function setup()
    slider = Slider("noodle", 1, 5, 1, WIDTH/2, HEIGHT/2, function() print(noodle) end)
    parameter.integer("noodle", 1, 5, 1, function() print(noodle) end)
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    slider:draw()
end

function touched(touch)
    slider:touched(touch)
end
--# Slider
Slider = class()

function Slider:init(variable, min, max, init, x, y, callback)
    self.variable = variable
    self.x, self.y = x, y
    self.min, self.max = min, max
    self.prevValue, self.curValue = init, init
    self.callback = callback
    self.length = 250
    self.sliderX = (self.x - self.length/2) + (self.length / (self.max - 1)) * (self.curValue - 1)
end

function Slider:draw()
    pushStyle()
    strokeWidth(2) stroke(127)
    line(self.x - self.length/2, self.y, self.x + self.length/2, self.y)
    strokeWidth(5) stroke(255)
    line(self.x - self.length/2, self.y, self.sliderX, self.y)
    strokeWidth(2) stroke(255) if self.touching then fill(255) else fill(0) end
    ellipse(self.sliderX, self.y, 20)
    fill(255, 151, 0, 255)
    local w,h = textSize(self.curValue)
    text(self.curValue, self.x + self.length/2 + 5 - w/2, self.y + 10 + h/2)
    local w,h = textSize(self.variable)
    text(self.variable, self.x - self.length/2 - 5 + w/2, self.y + 10 + h/2)
    popStyle()

    if self.touching then
        self.sliderX = math.max(math.min(CurrentTouch.x, self.x + self.length/2), self.x - self.length/2)
        self.curValue = math.floor((((self.sliderX - (self.x - self.length/2)) / self.length) 
            * (self.max - 1) + 1) + 0.49)
        if self.callback ~= nil and self.curValue ~= self.prevValue then
            _G[self.variable] = self.curValue
            self.callback()
            self.prevValue = self.curValue
        end
    end
end

function Slider:touched(touch)
    if touch.x > self.sliderX - 10 and touch.x < self.sliderX + 10
    and touch.y > self.y - 10 and touch.y < self.y + 10 then
        self.touching = true
    end
    
    if touch.state == ENDED then
        self.touching = false
        self.sliderX = (self.x - self.length/2) + 
            (self.length / (self.max - 1)) * (self.curValue - 1)
    end
end

@JakAttak Thanks! I will try it out!

what? the mini dress? :))

Can I use this code? I will give credit! : D