iparameter() docs and implementation don't agree

Minor, but confusing - I thought this was an issue with LoveCodify until I started digging…

So - if I do this:

sw = 2
iparameter(“sw”, 0, 8)

and run, sw will be 2, and the range will be zero to eight.

Problem is - the docs state that if the optional “initial” parameter isn’t passed, the parameter is set to the minimum value of the range. LoveCodify implemented it per docs, and my code broke. :frowning:

Now - easy workaround for me, I’ll just add the “initial” parameter - but we should either change the docs to reflect how it works (which is it will retain the value), or change the implementation to match the docs.

SOMEDAY I will figure out how to format code on this board. Someday.

Four spaces should do it (or a pre html tag).

As for the bug, I don’t think we ever tested that use case! I guess we just assumed you would use iparameter to define the variable, in that case I think it does set the parameter to the minimum value. The issue seems to be if its already defined.

I guess the best thing to do would be to change the docs to reflect the actual behaviour so we don’t break people’s existing code in an update.

Heh - I didn’t realize it would declare the variable for you; I just assumed you needed to deal with that. Mind you - I tend to read docs after I can’t get things to work. :slight_smile:

However you resolve it, I’ll be changing my code to use the initial parameter.

I actually suggest you initialize the variable to the minimum if it’s not nil - that should support both behaviors.

Good catch, we will change iparameter (and parameter) to initialize the variable to the minimum value.

Edit: The reason I won’t allow iparameter to use a variable’s current value is in case that variable is out of the defined range.

I’m sort of lost on this one.

I wanted a iparameter(“XRed”,-10,10,2)

It sets to 2 just fine but the lower bound is 1.

A work around is here


Is there a future change that’s pending or am I missing something?

Any bugs reported and fixed after November 5 didn’t make it into Codea 1.1.2 (as the updated was submitted by then) – Can you put this iparameter() bug on the issue tracker? https://bitbucket.org/TwoLivesLeft/codea/issues