Old 11-20-2018, 06:49 AM   #1
nikolalkc
Human being with feelings
 
nikolalkc's Avatar
 
Join Date: Feb 2017
Location: Belgrade, Serbia
Posts: 117
Default Is it possible to save ReaScript state even when REAPER restarts?

This is how my script looks like:

Code:
local state = tonumber(reaper.GetExtState("toggle-test","state"))
if state == nil then state = 0 end

if state == 0 then
	state = 1
elseif state == 1 then
	state = 0
end

reaper.SetExtState("toggle-test","state",state,true)
local self = ({reaper.get_action_context()})[4]
reaper.SetToggleCommandState(0, self, state)
When I create a toolbar button for this script it works fine.
Script has two states, on/off and that is reflected in toolbar button color.


The problem shows when I restart REAPER. ExtState is still on but the button does not show that until I click it again. How can I save this state to be reloaded when REAPER opens? I would like to avoid using sws global startup action.

Is this even possible?
Attached Images
File Type: gif demo.gif (7.1 KB, 55 views)
nikolalkc is offline   Reply With Quote
Old 11-20-2018, 08:03 AM   #2
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 608
Default

Create a new script, called:

Code:
__startup.lua
in your scripts-folder. This will be run automatically at startup.
In that script, you add the "Set Toggle-States"-codelines.
__________________
Ultraschall-API: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs for Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 11-20-2018, 09:14 AM   #3
nikolalkc
Human being with feelings
 
nikolalkc's Avatar
 
Join Date: Feb 2017
Location: Belgrade, Serbia
Posts: 117
Default

Thanks, I didn't know about that.
This will be useful.
nikolalkc is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.