Changing the Parameter maximum post-startup, how is it possible?

I take it this page does not exist?

https://bitbucket.org/TwoLivesLeft/codea/wiki/parameter

The problem:
I’m trying to make a certain parameter change its upper value dynamically
so that it always matches a number set by another parameter.

My understanding is that when you put parameters in the setup function it will only
setup the parameters once.

Thus anything that should change a parameter’s maximum after start up is thus ignored as it only goes there once.

Suffice it to say I’ve tried putting it in the draw function, the touch function, and a class init function (on separate occasions of coarse not all at once).

draw function results:
parameter gets set to 1 and can’t be moved.
Starting it with a 0 minimum? Makes 1 its maximum.

touch function results:
Starting it with a 0 minimum? Makes 1 its maximum unless you change the upper-limit parameter BEFORE YOU TAP THE SCREEN (caps for emphasis).

parameter maximum won’t change beyond initial setup and some how values affected by it are loss gradually if you were to persistently tap outside the parameter/output section of the screen.

init function results:
Starting it with a 0 minimum? Makes 1 its maximum unless you set it up in a separate class init that’s only accessed by way if special condition change the upper-limit parameter BEFORE YOU CHANGE THE PARAMETER (caps for emphasis).

However parameter maximum still won’t change beyond the initial setup.

On a side-note I quite like the way you don’t have to tap the screen to update everything with it in the init function.

I just wish there was some other way to get it to recognize that one parameter’s upper-limit has changed

Perhaps you could use clearParameters() then re-establish the same parameters with the settings you want? You are not constrained to calling these functions in setup().

Thanks for trying @mpilgrem but the results I posted earlier were not from setup they were from other locations. I thought I made that clear sorry for the confusion.

As for clearParameters()? I’ve tried that too.

@GenobiJuan parameters can only be set once, unless you call clearParameters (as @mpilgrem mentioned) and re-establish them. For example the following code will change the upper limit of “MyParameter”

function setup()
    parameter( "MyParameter", 0, 50 )
end

function draw()
end

function touched( touch )
    if touch.tapCount == 1 and touch.state == ENDED then 
        clearParameters()
        parameter("MyParameter", 0, 100 )
    end
end

If you slide the parameter before you touch the screen, it will only reach 50. After tapping the screen it should be able to reach 100.

You could redefine parameter(), iparameter() and clearParameters() to provide the functionality you seek.For example:


-- Warning: Some browsers (eg IE9 for Windows) may not render all of
-- the underscore characters in the code below. G has one in front of it.
-- Version 2012.06.30.12.15
do
	-- Preserve built-in functions
	local oldP = parameter
	local oldIP = iparameter
	local oldCP = clearParameters
	local pList = {}    -- Will hold the set i/parameters
	local pProp = {}    -- Will hold their properties

	-- Private generic helper
	local addP = function(isIParam, var, min, max, init)
		local old = oldP
		if isIParam then
			if init then init = math.modf(init) end
			if min then min = math.modf(min) end
			if max then max = math.modf(max) end
			old = oldIP
		end
		if not min then
            min = 0
            max = 1
            if isIParam then max = 10 end -- Handle iparameter with no max
        end
		if not max then -- Handle case of two arguments
            max = math.max(0, min)
            min = 0
            if isIParam then max = 10 end -- Handle iparameter with no max
        end
		if not pProp[var] then
			if not init then init = min end
			pProp[var] = {
				min = math.min(min, init),
				max = math.max(max, init),
				isIParam = isIParam}
			pList[#pList+1] = var
			old(var, min, max, init)
			return
		end
		local p = pProp
		local l = pList
		p[var] = {
			min = min,
			max = max,
			isIParam = isIParam}
		clearParameters()
		for i = 1, #l do
			local k = l[i]
			local v = p[k] 
			local i = _G[k]
			if isIParam then i = math.modf(i) end
			if k == var and init then i = init end
			if v.isIParam then
				iparameter(k, v.min, v.max, i)
			else
				parameter(k, v.min, v.max, i)
			end
		end
		return
	end

	-- Redefine parameter()
	parameter = function (var, min, max, init)
		addP(false, var, min, max, init)
    end

	-- Redefine iparameter()    
	iparameter = function (var, min, max, init)
		addP(true, var, min, max, init)
    end
    
	-- Redefine clearParameters()
	clearParameters = function ()
		pProp = {}
		pList = {}
		oldCP()
		return
	end        
end

-- Example of use
function setup()
    parameter("test1", 0, 100, 50)
    iparameter("itest1", 0, 100, 50)
    parameter("test2", 100, 200, 50)
    iparameter("itest2", 100, 200, 50)
    parameter("test3")
    iparameter("itest3")
end

function draw()
    background(40, 40, 50)
end

function touched(touch)
    if touch.state == BEGAN then
    parameter("test2", 0, 300)  -- Reset limits
    iparameter("test1", 0, 100) -- Change to an iparameter
    end
end

(Update) I’ve added a generic helper to reduce repetition. (Further update) Now correctly handles iparameter with no max, and case of two arguments.

In response to your opening comment about the wiki, @GenobiJuan, I have added pages, here and here, to extend what is documented in Codea’s in-app reference.