Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 11-20-2018, 06:49 AM   #1
nikolalkc
Human being with feelings
 
nikolalkc's Avatar
 
Join Date: Feb 2017
Location: Belgrade, Serbia
Posts: 338
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, 511 views)
nikolalkc is offline   Reply With Quote
Old 11-20-2018, 08:03 AM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
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.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada 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: 338
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 09:26 AM.


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