Home › Forums › General › Programming › this 'reset' only works after values have been changed?
Tagged: initial
- This topic has 4 replies, 2 voices, and was last updated 6 years, 11 months ago by human fly.
-
AuthorPosts
-
June 8, 2017 at 6:10 am #72307
i have a ‘reset’ function triggered by button with
‘Called when modulator value changes’ or ‘Mouse Down’-
but on Panel load, it will initially only work after
the values it resets have been changed.it is for resetting the values of envelope modulators to
default values. i can’t see why it doesn’t work initially.
here is an example:--called when modulator value changes function resetPitchEG(m,v) --This stops issues during panel bootup if panel:getRestoreState() or panel:getProgramState() then return end --reset envelope local reset= panel:getModulator("resetPitchEG"):getValue() local tabs= panel:getComponent ("tabs_Envelopes") --change tab tabs:setPropertyInt ("uiTabsCurrentTab", 0) if reset~=nil then --time for k= 1,4 do modul1=panel:getModulatorWithProperty("modulatorCustomIndex",1) modul2=panel:getModulatorWithProperty("modulatorCustomIndex",2) modul3=panel:getModulatorWithProperty("modulatorCustomIndex",3) modul4=panel:getModulatorWithProperty("modulatorCustomIndex",4) if tab =="tabs_Envelopes" then modul1:setModulatorValue(50,false,false,false) modul2:setModulatorValue(50,false,false,false) modul3:setModulatorValue(50,false,false,false) modul4:setModulatorValue(50,false,false,false) end end --level for k=5,9 do modul5=panel:getModulatorWithProperty("modulatorCustomIndex",5) modul6=panel:getModulatorWithProperty("modulatorCustomIndex",6) modul7=panel:getModulatorWithProperty("modulatorCustomIndex",7) modul8=panel:getModulatorWithProperty("modulatorCustomIndex",8) modul9=panel:getModulatorWithProperty("modulatorCustomIndex",9) if tab =="tabs_Envelopes" then modul5:setModulatorValue(0,false,false,false) modul6:setModulatorValue(0,false,false,false) modul7:setModulatorValue(0,false,false,false) modul8:setModulatorValue(0,false,false,false) modul9:setModulatorValue(0,false,false,false) end end end end
this works fine the rest of the time. it is a bit long like this;
if i can learn to iterate, i can improve it, but i also want access
to individual values. i suspect i’m declaring wrong: do i need to
initialise each modulator or something like that?
ie: if i randomize them first, it will reset. if i just click
‘reset’, nothing happens.any thoughts?
ps: condition ‘if reset~=nil’ here is a bit ‘meh..’, i don’t
know if it really needs to getValue. could be something
better here too.pps: this is applying values to modulators in a CustomGroup.
i’m using index ranges to separate ‘time’ and ‘level’ modu-
lators. they could all be addressed together really.June 8, 2017 at 9:55 am #72308this iterations makes no sense (why the for loop if you don’t loop there):
——————————————————————————-
–time
for k= 1,4 do
modul1=panel:getModulatorWithProperty(“modulatorCustomIndex”,1)
modul2=panel:getModulatorWithProperty(“modulatorCustomIndex”,2)
modul3=panel:getModulatorWithProperty(“modulatorCustomIndex”,3)
modul4=panel:getModulatorWithProperty(“modulatorCustomIndex”,4)
——————————————————————————-Read about the “for loop” and read about arrays/tables. This way you could store your variables in a table and do the iteration on its elements.
modul = {}
for k= 1,4 do modul[k]=panel:getModulatorWithProperty(“modulatorCustomIndex”,k)
endthis will loop thru elements 1-4 of your table. DO the same for the other variables.
Cheers!
June 8, 2017 at 9:11 pm #72310ah, ok. it’s true i’m still unsure about ‘for’ iterations.
i went for it like that to try to do it in one go, – just to
get something working! the renumbering of the ‘modul’s
was because i needed different values for some of them,
not all the same. it is adequate for what i need, for the
time being.is there anything you can see in there that would stop it
from operating on first-loaded values? it resets fine
after i’ve changed any parameter.June 8, 2017 at 9:20 pm #72312in fact, i’m still not in the habit of using tables at this stage.
was getting to know ‘custom groups’.June 11, 2017 at 10:52 am #72335*bump* re: why is reset working before values changed.
can you see anything that is preventing that?
maybe it would work if i declared modulators on startup.but how about a little ‘local’ fix for it here? just for
argument’s sake? 🙂
(and disregarding inelegance of the whole thing) -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.