Old 07-16-2018, 03:24 AM   #1
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 811
Default Saving TrackGUIDs to table [SOLVED]

Hi!

Have started to learn how to make Reascripts with Lua,
and is now at a point there I smack my head against the
wall. I am trying to save some selected tracks GUIDS to
a table but get an error I dont understand - maybe its
the hot summer...

My code:
Code:
function SaveSelectedTracksGUID ()
  -- Get the number of selected tracks in the project
  number_of_selected_tracks = reaper.CountSelectedTracks(0)

  selected_tracks_table = {} -- init table

  for i = 0, number_of_selected_tracks  do  -- collect selected track

    tr = reaper.GetSelectedTrack(0, i)

    Msg(tr)

    track_guid = reaper.GetTrackGUID( tr )

    Msg(track_guid)

    --Store this tracks GUID to end of table
    selected_tracks_table[#selected_tracks_table + 1] = track_guid 
 
   Msg(selected_tracks_table[i])

  end

end
And the error is: bad argument #1 to 'GetTrackGUID' (MediaTrack expected)

I am doing something wrong - but what?
Have Googled but couldn't find any solution.

Anyone seeing what the problem is?

Regards
Thomas
__________________
ToDoList Obliques MusicMath Donation Some of mine and my friends music projects on Spotify

Last edited by tompad; 07-17-2018 at 02:58 AM.
tompad is offline   Reply With Quote
Old 07-16-2018, 04:11 AM   #2
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Hey tompad,

yes, you have to change "number_of_selected_tracks" in the for loop to "number_of_selected_tracks-1", since your counter starts with 0.
reaper.GetTrackGUID(tr) will then try to get a track that does not exist and returns "nil".

Code:
for i = 0, number_of_selected_tracks-1  do  -- collect selected track
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 07-16-2018, 04:24 AM   #3
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 811
Default

Quote:
Originally Posted by _Stevie_ View Post
Hey tompad,

yes, you have to change "number_of_selected_tracks" in the for loop to "number_of_selected_tracks-1", since your counter starts with 0.
reaper.GetTrackGUID(tr) will then try to get a track that does not exist and returns "nil".

Code:
for i = 0, number_of_selected_tracks-1  do  -- collect selected track
Thanks Stevie!

The error dialog has disappeared - but in console I got a nil (3 tracks selected):
Code:
userdata: 0x1d94cc0
{192004BA-37F1-03F1-10FE-DB7C539F408F}
nil
userdata: 0x1da2400
{74C5F340-C80D-8D7D-2FC1-88791E6DA9E0}
{192004BA-37F1-03F1-10FE-DB7C539F408F}
userdata: 0x2294190
{D0B305AC-9434-7308-FF2F-78CB302425B5}
{74C5F340-C80D-8D7D-2FC1-88791E6DA9E0}
__________________
ToDoList Obliques MusicMath Donation Some of mine and my friends music projects on Spotify
tompad is offline   Reply With Quote
Old 07-16-2018, 04:27 AM   #4
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 811
Default

Never mind!! I got it - needed to make +1 in Msg also!

Msg(selected_tracks_table[i+1])!

Thanks Stevie!
__________________
ToDoList Obliques MusicMath Donation Some of mine and my friends music projects on Spotify
tompad is offline   Reply With Quote
Old 07-16-2018, 04:32 AM   #5
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 811
Default

If I want to take this table-thing one step further....
How can I put 2 (or more) values in every "table-row"?

TrackGUID and another value, say TrackName - so every
saved TrackGUID have the trackname associated with it?
__________________
ToDoList Obliques MusicMath Donation Some of mine and my friends music projects on Spotify
tompad is offline   Reply With Quote
Old 07-16-2018, 04:42 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

You can put tables in tables.
Code:
selected_tracks_table[#selected_tracks_table + 1] = {
    guid = track_guid, 
    name = track_name
}
Accessing them then becomes:
Code:
Msg(selected_tracks_table[n].guid .. ":\t" .. selected_tracks_table[n].name
__________________
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-16-2018, 06:56 AM   #7
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 811
Default

Quote:
Originally Posted by Lokasenna View Post
You can put tables in tables.
Code:
selected_tracks_table[#selected_tracks_table + 1] = {
    guid = track_guid, 
    name = track_name
}
Accessing them then becomes:
Code:
Msg(selected_tracks_table[n].guid .. ":\t" .. selected_tracks_table[n].name
Voaw!! Smooooth!

Thanks Lokasenna!
__________________
ToDoList Obliques MusicMath Donation Some of mine and my friends music projects on Spotify
tompad 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 04:09 PM.


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