Johnathon Posted July 1, 2015 Share Posted July 1, 2015 I'm working on a mod (or more specifically a script for a mod) that will better randomize songlists more like a normal media player where it won't repeat a song until every song in the playlist has already been played. For some reason, I can't get the NVSE array functions to work and I can't for the life of me figure out why it is. This is the script (not complete, but should function-ish) ScriptName JSTexasRangersRadioSCRIPT short nStory; short bDoTransition; short NextSonga; short nTracksPlayed; short playNextNow; short RandGen; short TrackCount; array_var aPlayedSongs Begin _GameMode if aPlayedSongs == 0; set TrackCount to 92; set playNextNow to 1 let aPlayedSongs := Ar_Construct "array" set NextSonga to 1; endif if playNextNow == 0; Not time to play the next track yet. Exit the script. return elseif playNextNow; Time to randomly select the next track. if eval (Ar_Find NextSonga, aPlayedSongs) == Ar_BadNumericIndex; THIS IS THE LINE WITH ISSUES ; It's not in the array. We need to add it. Ar_Append aPlayedSongs, NextSonga if eval Ar_Size aPlayedSongs == TrackCount Ar_Resize aPlayedSongs 0 endif endif ; Time to generate a random number. set RandGen to rand 1, TrackCount; if eval (Ar_Find RandGen, aPlayedSongs) == Ar_BadNumericIndex set playNextNow to 0 set NextSonga to RandGen else return endif endif EndI cannot get this script to compile. When I try to save it, it tells me that line 23 cannot be parsed. Now, if I replace "NextSonga" with a number, then the compiler doesn't complain about the line anymore, but I need it to check if the variable's value exists in the array. Any advice would be greatly appreciated. Link to comment Share on other sites More sharing options...
Fallout2AM Posted July 2, 2015 Share Posted July 2, 2015 (edited) What about splitting the condition in two Let iMyTempResult := Ar_Find NextSonga, aPlayedSongs if iMyTempResult > -1 ... ; I guess it's in the arrayPretty sure you can avoid to use Compiler Override. Edited July 2, 2015 by Fallout2AM Link to comment Share on other sites More sharing options...
Johnathon Posted July 2, 2015 Author Share Posted July 2, 2015 What about splitting the condition in two Let iMyTempResult := Ar_Find NextSonga, aPlayedSongs if iMyTempResult > -1 ... ; I guess it's in the arrayPretty sure you can avoid to use Compiler Override. The compiler override was something I tried to see if it would fix the issue. Forgot to remove it when that didn't fix it. Thanks. I tried to do it separate as well and the error occurs on the let line saying it couldn't compile it still. Not sure why it is doing that. Link to comment Share on other sites More sharing options...
Fallout2AM Posted July 3, 2015 Share Posted July 3, 2015 (edited) My best guess is in the variables you're using. How did you declare them? directly copy pasted from the code I was writing tonight. As you can see it's the same. Let iCheck := ar_find rActor aaHP.arBars[0]iCheck is an intrActor is a refarBars is a bidimensional arrayEDIT silly me, you even wrote them... *lol* really, I wouldn't have ideas. Except I never use shorts since they're unuseful Edited July 3, 2015 by Fallout2AM Link to comment Share on other sites More sharing options...
Fallout2AM Posted July 3, 2015 Share Posted July 3, 2015 EDIT: it compiles, the error was in another place. ScriptName JSTexasRangersRadioSCRIPT short nStory; short bDoTransition; short NextSonga; short nTracksPlayed; short playNextNow; short RandGen; short TrackCount; array_var aPlayedSongs Begin _GameMode if aPlayedSongs == 0; set TrackCount to 92; set playNextNow to 1 let aPlayedSongs := Ar_Construct "array" set NextSonga to 1; endif if playNextNow == 0; Not time to play the next track yet. Exit the script. return elseif playNextNow; Time to randomly select the next track. if eval (Ar_Find NextSonga, aPlayedSongs) == Ar_BadNumericIndex; THIS IS THE LINE WITH ISSUES ; It's not in the array. We need to add it. Ar_Append aPlayedSongs, NextSonga if eval (Ar_Size aPlayedSongs) == TrackCount ; HERE WAS THE ERROR Ar_Resize aPlayedSongs 0 endif endif ; Time to generate a random number. set RandGen to rand 1, TrackCount; if eval (Ar_Find RandGen, aPlayedSongs) == Ar_BadNumericIndex set playNextNow to 0 set NextSonga to RandGen else return endif endif End Link to comment Share on other sites More sharing options...
Johnathon Posted July 3, 2015 Author Share Posted July 3, 2015 EDIT: it compiles, the error was in another place. ScriptName JSTexasRangersRadioSCRIPT short nStory; short bDoTransition; short NextSonga; short nTracksPlayed; short playNextNow; short RandGen; short TrackCount; array_var aPlayedSongs Begin _GameMode if aPlayedSongs == 0; set TrackCount to 92; set playNextNow to 1 let aPlayedSongs := Ar_Construct "array" set NextSonga to 1; endif if playNextNow == 0; Not time to play the next track yet. Exit the script. return elseif playNextNow; Time to randomly select the next track. if eval (Ar_Find NextSonga, aPlayedSongs) == Ar_BadNumericIndex; THIS IS THE LINE WITH ISSUES ; It's not in the array. We need to add it. Ar_Append aPlayedSongs, NextSonga if eval (Ar_Size aPlayedSongs) == TrackCount ; HERE WAS THE ERROR Ar_Resize aPlayedSongs 0 endif endif ; Time to generate a random number. set RandGen to rand 1, TrackCount; if eval (Ar_Find RandGen, aPlayedSongs) == Ar_BadNumericIndex set playNextNow to 0 set NextSonga to RandGen else return endif endif End I still get the same cannot parse on line 23. The error seems to be in using a variable that's a short rather than a ref for the search value, which is odd since it works fine if I use an actual number and the scripting examples all say it can be a number for an array search. Link to comment Share on other sites More sharing options...
Fallout2AM Posted July 3, 2015 Share Posted July 3, 2015 (edited) then there's a kind of magic, because I compiled that correctly in my GECK... :wink: with and without Compiler Override Edited July 3, 2015 by Fallout2AM Link to comment Share on other sites More sharing options...
Johnathon Posted July 4, 2015 Author Share Posted July 4, 2015 then there's a kind of magic, because I compiled that correctly in my GECK... :wink: with and without Compiler OverrideHuh... Must've had a messed up version of NVSE installed. Did a reinstall of everything and now it compiles just fine. Thanks so much for the help! Link to comment Share on other sites More sharing options...
Fallout2AM Posted July 4, 2015 Share Posted July 4, 2015 you're welcome :) Link to comment Share on other sites More sharing options...
Recommended Posts