Jump to content

Mod Creation - NVSE Array Assistance Needed


Johnathon

Recommended Posts

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
End

I 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

What about splitting the condition in two

Let iMyTempResult := Ar_Find NextSonga, aPlayedSongs
if iMyTempResult > -1
   ... ; I guess it's in the array

Pretty sure you can avoid to use Compiler Override.

Edited by Fallout2AM
Link to comment
Share on other sites

What about splitting the condition in two

Let iMyTempResult := Ar_Find NextSonga, aPlayedSongs
if iMyTempResult > -1
   ... ; I guess it's in the array

Pretty 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

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 int

rActor is a ref

arBars is a bidimensional array

EDIT silly me, you even wrote them... *lol* really, I wouldn't have ideas. Except I never use shorts since they're unuseful

Edited by Fallout2AM
Link to comment
Share on other sites

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

 

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

then there's a kind of magic, because I compiled that correctly in my GECK... :wink: with and without Compiler Override

Huh... 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...