irswat Posted November 9, 2016 Share Posted November 9, 2016 (edited) This loop is infinite. The only reason I can think of is that CurrentDumpWordIndex is being reset everytime I call GetWord(). If I call a function do the local variables in the parent function retain their value, or get reset, when the child function returns a value? while (LoopCounter<=DumpLineCount) CurrentLine=GetLine(CurrentDump, LoopCounter, DumpLineCount) debug.trace("Current Line: " + CurrentLine) WordsOnCurrentLine=GetNumWords(CurrentLine) debug.trace("Number of words on current line: " + WordsOnCurrentLine) CurrentWordIndex=1 while (CurrentWordIndex<=WordsOnCurrentLine) ; ;Get word y on line x CurrentWord=GetWord(CurrentLine, WordsOnCurrentLine, CurrentWordIndex) debug.notification("Word " + CurrentDumpWordIndex + ": " + CurrentWord) debug.trace("Word " + CurrentDumpWordIndex + ": " + CurrentWord) ; ;store word y in array ; SVE_DumpArray[CurrentDumpWordIndex]=CurrentWord CurrentWordIndex+=1 ; CurrentDumpWordIndex+=1 endWhile LoopCounter=LoopCounter+1 e.g. in this example DumpLineCount==3; WordsOnCurrentLine==8; LoopCounter is initialized at 1, and CurrentDumpIndex at 0. If I comment out the nested while loop the outter while loop goes 3 times, as it should. It prints each line, and then the total number of words on each line, and then goes to the next line. Perfect. When I activate the nested while loop which is supposed to read individual words from each line and store them into a string array, 1 line is read, and that the line contains 8 words, but it never seems to even get so far as to print the Word + CurrentDumpIndex + CurrentWord.Any ideas?EDIT: On second thought, this would suggest the loop is getting stuck in the child function GetWord(). Nevertheless the question remains: do local variables retain values after returning from a child function?Here is the GetWord: string function GetWord(string SVE_CurrentLine, int WordsOnLine, int WordNumber) int EndOfWord=0 int NullCharIndex=0 int WordParserStart=0 int WordsSkipped=WordNumber - 1 int WordsToSkip=(WordsOnLine-WordNumber) bool EndOfLine=false string WordReturn ;parse distinct words from first line [x]-' '\ ;for x=1;x<=WordCount;x++ While (WordsSkipped<=WordsToSkip) EndOfWord=Find(SVE_CurrentLine," ", WordParserStart) ;accounting for space NullCharIndex=Find(SVE_CurrentLine,"/n",WordParserStart) if (NullCharIndex<EndOfWord) ;end of line EndOfLine=true endif if !EndOfLine WordReturn=Substring(SVE_CurrentLine, WordParserStart, EndOfWord) WordParserStart=EndOfWord+1 WordsSkipped+=1 endif endWhile return WordReturn endFunction Edited November 9, 2016 by irswat Link to comment Share on other sites More sharing options...
irswat Posted November 10, 2016 Author Share Posted November 10, 2016 (edited) "/n" is in the text file that I'm reading from, but I am deliberately not dumping it into the string SVE_CurrentLine. Consequently NullCharIndex is returning -1 always. And -1 will always be greater than a positive number. Next problem is weird. Good news is once this function is completed I will have some neat new functions for StringsUtil for SKSE if they wanted to implement them. if (NullCharIndex<EndOfWord) ;end of line EndOfLine=true endif Edited November 10, 2016 by irswat Link to comment Share on other sites More sharing options...
FrankFamily Posted November 10, 2016 Share Posted November 10, 2016 If "do local variables retain values after returning from a child function?" means something like this (very simplified) Function stuff() Int SomeVar = 847 String SomeStuff = SomeExternalFunction(parameters) trace(Somevar) => this still is 847 EndFunctionThen yes, calling another function should not cause all the local variables of the function/whatever to reset. Not sure where the problem is with that script but it's late, i'm sleepy and there are a lot of variables! so i may have missed it... DumpLineCount and WordsOnCurrentLine are finite numbers and LoopCounter and CurrentWordIndex are being incremented in each loop, i don't see why it would be infinite. Link to comment Share on other sites More sharing options...
irswat Posted November 10, 2016 Author Share Posted November 10, 2016 (edited) the script is fixed and working correctly. Thanks FF. I figured the problem out and posted above Edited November 10, 2016 by irswat Link to comment Share on other sites More sharing options...
Recommended Posts