Old 07-15-2018, 08:32 PM   #1
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default Q: String to Array

In this scrip I need to convert the notenums string to an array for Cnotes to convert the chord to Reascale.


notenums outputs the string 0, 4, 7, 10

@ Line 398
Cnotes needs this format
Cnotes = {0, 4, 7, 10}
Attached Files
File Type: zip selected-notes-to-chord name-2.zip (4.3 KB, 55 views)
MusoBob is offline   Reply With Quote
Old 07-15-2018, 09:05 PM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

gmatch is your friend:
Code:
local str = "0, 4, 7, 10"
local t = {}
for num in string.gmatch(str, "%d+") do
    t[#t+1] = tonumber(num)
end
It iterates through the input string for every instance that matches the given pattern. In this case, %d means "a numeral" and + tells it "grab as many as you can". The spaces and/or commas break up that sequence, so it can get each value separately.

Personally I'd rewrite it to put them in a table to start with and use table.concat to make a string for the few occasions where you need one.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 07-15-2018, 10:52 PM   #3
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 2,643
Default

Thanks again I appreciate your help !
It's all working now, just got to tweak the Reascale "if then's" and it should be good to go.
I'm just combining all these scripts with your GUI that I will upload for users.
Will be glade to get back to the music side of things as this is my first attempt at scripting that I knew nothing about, and it's easy to get bogged down in it all.
MusoBob 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 02:29 PM.


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