0
votes

I want to take a CSV that has four parts: Some text to be displayed, a priority rating, a duration in ms, and a "start time" in ms Then select from the rows the row with the lowest start time (or in case of a tie, the one with the highest priority).

Whenever I try to run my current code, it returns an error saying that my StrSplit line has a Blank Parameter.

I've tried doing a separate Read Loop that populates the array, then using the built-in Index variables to track each one. I suspect that the issue is that an array is often just a set of pieces of data separated by commas—and having a row that has commas in it might cause a problem—so it's possible my loops is running once, then returns a blank split on the second try.

; Create empty array to be read to
StringArray := []

;~ ; Loop through CSV file and append each line to the array
Loop, Read, Gamestrings.csv
    {
        StringArray.Push(A_LoopReadLine)
    }

return

; New Table Option
;~ StringArray := Object()
;~ Loop, Read, Gamestrings.csv
    ;~ StringArray[A_Index] := StrSplit(A_LoopReadLine, ",")
;~ return

;Set up function/label
; Outerloop checks for Indices in array only if there is no active string, if there is an active string, loop portion skipped in favor of checking SplitStartTime against global counter until a string is displayed, which sets activestring to empty

StartCheck:
{
    for index, element in StringArray {
        BaseRow := StringArray[A_Index]
        SplitRow := StrSplit(BaseRow, ",",)
        SplitStartTime := SplitRow[4]
        SplitPriority := SplitRow[2]
    }
        if (CurrentLowest == false OR SplitStartTime < CurrentLowest) {
            ;Create initial Active String for comparisons
            ActiveString := StringArray[A_index]
            HighestPriority := SplitPriority
            CurrentLowest := SplitStartTime
            ActiveIndex := A_index
    }
        ;~ else if (SplitStartTime < CurrentLowest) {
            ;Replace Global Variables with current line OR could use StringArray index to point to which line should be active and save on using so many variables
            ;~ ActiveString := StringArray[A_index]
            ;~ DisplayText := SplitRow[1]
            ;~ PriorityOne := SplitRow[2]
            ;~ DisplayDuration := SplitRow[3]
            ;~ HighestPriority := SplitPriority
            ;~ CurrentLowest := SplitStartTime
    ;~ }
        else if (SplitStartTime = CurrentLowest AND HighestPriority < SplitPriority) {
            ActiveString := StringArray[A_index]
            HighestPriority := SplitPriority
            ActiveIndex := A_index

The end goal of the entire script is to display a line of text for a specific duration, then strike it from the array. The array is populated from the CSV file. Only one line can be displayed at once, so I have a pseudo-timer rigged as a global variable that works for that, but can't even test the functionality of the script, due to the blank parameter error I'm getting from the StrSplit line.

I know there are other problems—any help is appreciated.

1

1 Answers

0
votes

Remove the extra comma in the line

SplitRow := StrSplit(BaseRow, ",",)

So, it should be

SplitRow := StrSplit(BaseRow, ",")