irswat Posted November 6, 2016 Share Posted November 6, 2016 (edited) Apparently I'm an idiot and don't know scripting. I can't figure out how to pass and return variables correctly. Scriptname SVE_ParserEngine extends quest Import StringUtil FormList Property ShoutFormList Auto FormList Property SpellFormList Auto FormList Property CommandFormList Auto FormList Property ArmorFormList Auto FormList Property ArrowFormList Auto FormList Property WeaponFormList Auto FormList Property SummonFormList Auto Actor Property PlayerRef Auto Actor Property TargetRef Auto ;Event OnInit() ; if ((SVE_DumpArray[0]!="initialized") || (!SVE_DumpArray[0])) ; string[] SVE_DumpArray=new string[31] ; SVE_DumpArray[1]="initialized" ; endif ;endEvent function Main() ;declarations string CurrentDump string ToPrint STRING CurrentLine int DumpLineCount int LoopCounter=1 int CurrentWordIndex int WordsOnCurrentLine ;implement "mic" button string[] SVE_DumpArray=new string[31] CurrentDump=Dump_PO() DumpLineCount=GetNumLines(string CurrentDump) while (LoopCounter<=DumpLineCount) CurrentLine=GetLine(string CurrentDump) WordsOnCurrentLine=GetNumWords(string CurrentLine) CurrentWordIndex=1 while(CurrentWordIndex<=WordsOnCurrentLine) SVE_DumpArray[LoopCounter+1]=GetWord(string CurrentLine) CurrentWordIndex+=1 endWhile LoopCounter+=1 endWhile ;array should now be filled with contents of string ;debug test LoopCounter=1 Debug.Notification("SVE_Parsing of string should be completed.") Debug.Notification("Printing array") while (LoopCounter<=DumpLineCount) CurrentLine=GetLine(string CurrentDump) WordsOnCurrentLine=GetNumWords(string CurrentLine) CurrentWordIndex=1 while(CurrentWordIndex<=WordsOnCurrentLine) ToPrint=SVE_DumpArray[LoopCounter+1] Debug.Notification(ToPrint) CurrentWordIndex=CurrentWordIndex+1 endWhile LoopCounter=LoopCounter+1 endWhile endfunction function Dump_PO() ;shoutout to MinionMaster for helping me understand the syntax and Find the right functions in MiscUtil.psc ;this function is his work string SVE_PO string sDatafileName = "data/SVE_PI.txt" if MiscUtil.FileExists(sDatafileName) SVE_PO = MiscUtil.ReadFromFile (sDatafileName) MiscUtil.WriteToFile(sDatafileName, "/delete", true, false) endif return SVE_PO endfunction function GetNumLines(string SVE_PO) ;Find out how many distinct lines are in the string int LineCountParserIndex=0 int LineCounter=0 int LineCount=0 int SVE_PO_End SVE_PO_End=Find(SVE_PO,"/delete",LineCountParserIndex) ;end of dump file while (SVE_PO_End==-1) ;delete not found on this line LineCounter=Find(SVE_PO, "/n", LineCountParserIndex) ;end of line if (LineCounter==-1) ;redundancy check for end of dump SVE_PO_End=Find(SVE_PO, "/delete", LineCountParserIndex) ;end of dump file endif if (SVE_PO_End==-1) LineCount=LineCount+1 LineCountParserIndex=LineCounter+3 endif endWhile if SVE_PO_END!=-1 ;end of dump return LineCount endif endFunction function GetLine(string SVE_PO) int EndOfLine=0 int LineParserStart=0 ;get length of first line [0]-"/n" EndOfLine=Find(SVE_PO, "/n", LineParserStart) EndOfLine-=2 ;accounting for carriage return ;gets the content of a line LineReturn=Substring(SVE_PO, LineParserStart, EndOfLine) ;updates parser starting index to next line (e.g "/n +3") LineParserStart=EndOfLine+3 ;accounting for carriage return return LineReturn endFunction function GetNumWords(string SVE_CurrentLine) ;Find out how many words are on the line int WordBeginningIndex=0 ;beginning of the word index int SpaceIndex=0 ;end of the word index int WordCount=0 ;number of words on a line int LineEnd=Find(SVE_CurrentLine, "/n", WordCountParserIndex) ;Finds index of null character/end of line while (SpaceIndex!=-1) SpaceIndex=Find(SVE_CurrentLine, " ", WordBeginningIndex) if SpaceIndex!=-1 ;space found WordCount+=1 WordBeginningIndex+=1 ;space + 1 endif endWhile return WordCount endFunction function GetWord(string SVE_CurrentLine) int EndOfWord=0 int WordParserStart=0 string WordReturn ;parse distinct words from first line [x]-' '\ ;for x=1;x<=WordCount;x++ EndOfWord=Find(LineReturn," ", WordParserStart) ;accounting for space EndOfWord-=1 WordReturn=Substring(LineReturn, WordParserStart, EndOfWord) WordParserStart=EndOfWord+2 return WordReturn endFunction compiler output: ...SVE_ParserEngine.psc(39,27): mismatched input 'string' expecting RPAREN...SVE_ParserEngine.psc(39,45): required (...)+ loop did not match anything at input ')'...SVE_ParserEngine.psc(43,22): mismatched input 'string' expecting RPAREN...SVE_ParserEngine.psc(43,40): required (...)+ loop did not match anything at input ')'...SVE_ParserEngine.psc(44,33): mismatched input 'string' expecting RPAREN...SVE_ParserEngine.psc(44,51): required (...)+ loop did not match anything at input ')'...SVE_ParserEngine.psc(48,40): mismatched input 'string' expecting RPAREN...SVE_ParserEngine.psc(48,58): required (...)+ loop did not match anything at input ')'...SVE_ParserEngine.psc(65,22): mismatched input 'string' expecting RPAREN...SVE_ParserEngine.psc(65,40): required (...)+ loop did not match anything at input ')'...SVE_ParserEngine.psc(66,33): mismatched input 'string' expecting RPAREN...SVE_ParserEngine.psc(66,51): required (...)+ loop did not match anything at input ')' everywhere that I try to call a function to fill a variable in the main function it is throwing this error. Edited November 6, 2016 by irswat Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 6, 2016 Share Posted November 6, 2016 Not sure if this is what the compiler is complaining about but it might be. You have it in several locations, I'll just provide one example. DumpLineCount=GetNumLines(string CurrentDump) You have the function GetNumLines defined to accept a string variable. As a result when you want to pass a value into that function, you simply put your value or variable in the parameter location. You do not define the type again. The aforementioned line should actually be: DumpLineCount=GetNumLines(CurrentDump) Link to comment Share on other sites More sharing options...
irswat Posted November 6, 2016 Author Share Posted November 6, 2016 (edited) revised code: Scriptname SVE_ParserEngine extends quest Import StringUtil FormList Property ShoutFormList Auto FormList Property SpellFormList Auto FormList Property CommandFormList Auto FormList Property ArmorFormList Auto FormList Property ArrowFormList Auto FormList Property WeaponFormList Auto FormList Property SummonFormList Auto Actor Property PlayerRef Auto Actor Property TargetRef Auto ;Event OnInit() ; if ((SVE_DumpArray[0]!="initialized") || (!SVE_DumpArray[0])) ; string[] SVE_DumpArray=new string[31] ; SVE_DumpArray[1]="initialized" ; endif ;endEvent function Main() ;declarations string CurrentDump string ToPrint string CurrentLine int DumpLineCount int LoopCounter=1 int CurrentWordIndex int WordsOnCurrentLine ;implement "mic" button string[] SVE_DumpArray=new string[31] CurrentDump=Dump_PO() DumpLineCount=GetNumLines(CurrentDump) while (LoopCounter<=DumpLineCount) CurrentLine=GetLine(CurrentDump) WordsOnCurrentLine=GetNumWords(CurrentLine) CurrentWordIndex=1 while(CurrentWordIndex<=WordsOnCurrentLine) SVE_DumpArray[LoopCounter+1]=GetWord(CurrentLine) CurrentWordIndex+=1 endWhile LoopCounter+=1 endWhile ;array should now be filled with contents of string ;debug test LoopCounter=1 Debug.Notification("SVE_Parsing of string should be completed.") Debug.Notification("Printing array") while (LoopCounter<=DumpLineCount) CurrentLine=GetLine(CurrentDump) WordsOnCurrentLine=GetNumWords(CurrentLine) CurrentWordIndex=1 while(CurrentWordIndex<=WordsOnCurrentLine) ToPrint=SVE_DumpArray[LoopCounter+1] Debug.Notification(ToPrint) CurrentWordIndex=CurrentWordIndex+1 endWhile LoopCounter=LoopCounter+1 endWhile endfunction function Dump_PO() ;shoutout to MinionMaster for helping me understand the syntax and Find the right functions in MiscUtil.psc ;this function is his work string SVE_PO string sDatafileName = "data/SVE_PI.txt" if MiscUtil.FileExists(sDatafileName) SVE_PO = MiscUtil.ReadFromFile (sDatafileName) MiscUtil.WriteToFile(sDatafileName, "/delete", true, false) endif return SVE_PO endfunction function GetNumLines(string SVE_PO) ;Find out how many distinct lines are in the string int LineCountParserIndex=0 int LineCounter=0 int LineCount=0 int SVE_PO_End SVE_PO_End=Find(SVE_PO,"/delete",LineCountParserIndex) ;end of dump file while (SVE_PO_End==-1) ;delete not found on this line LineCounter=Find(SVE_PO, "/n", LineCountParserIndex) ;end of line if (LineCounter==-1) ;redundancy check for end of dump SVE_PO_End=Find(SVE_PO, "/delete", LineCountParserIndex) ;end of dump file endif if (SVE_PO_End==-1) LineCount=LineCount+1 LineCountParserIndex=LineCounter+3 endif endWhile return LineCount endFunction function GetLine(string SVE_PO) int EndOfLine=0 int LineParserStart=0 string LineReturn ;get length of first line [0]-"/n" EndOfLine=Find(SVE_PO, "/n", LineParserStart) EndOfLine-=2 ;accounting for carriage return ;gets the content of a line LineReturn=Substring(SVE_PO, LineParserStart, EndOfLine) ;updates parser starting index to next line (e.g "/n +3") LineParserStart=EndOfLine+3 ;accounting for carriage return return LineReturn endFunction function GetNumWords(string SVE_CurrentLine) ;Find out how many words are on the line int WordBeginningIndex=0 ;beginning of the word index int SpaceIndex=0 ;end of the word index int WordCount=0 ;number of words on a line int LineEnd=Find(SVE_CurrentLine, "/n", WordBeginningIndex) ;Finds index of null character/end of line while (SpaceIndex!=-1) SpaceIndex=Find(SVE_CurrentLine, " ", WordBeginningIndex) if SpaceIndex!=-1 ;space found WordCount+=1 WordBeginningIndex+=1 ;space + 1 endif endWhile return WordCount endFunction function GetWord(string SVE_CurrentLine) int EndOfWord=0 int WordParserStart=0 string WordReturn ;parse distinct words from first line [x]-' '\ ;for x=1;x<=WordCount;x++ EndOfWord=Find(SVE_CurrentLine," ", WordParserStart) ;accounting for space EndOfWord-=1 WordReturn=Substring(SVE_CurrentLine, WordParserStart, EndOfWord) WordParserStart=EndOfWord+2 return WordReturn endFunction compiler error: ...\SVE_ParserEngine.psc(41,1): type mismatch while assigning to a int (cast missing or types unrelated)...\SVE_ParserEngine.psc(46,2): type mismatch while assigning to a int (cast missing or types unrelated)...\SVE_ParserEngine.psc(68,2): type mismatch while assigning to a int (cast missing or types unrelated)...\SVE_ParserEngine.psc(94,1): cannot return a string from dump_po, the function does not return a value...\SVE_ParserEngine.psc(120,1): cannot return a int from getnumlines, the function does not return a value...\SVE_ParserEngine.psc(141,1): cannot return a string from getline, the function does not return a value...\SVE_ParserEngine.psc(160,1): cannot return a int from getnumwords, the function does not return a value...\SVE_ParserEngine.psc(175,1): cannot return a string from getword, the function does not return a value I'm definitely returning values from these functions, and they match the variable types defined and expected in the main function. I don't get it. Edited November 6, 2016 by irswat Link to comment Share on other sites More sharing options...
mrpwn Posted November 6, 2016 Share Posted November 6, 2016 You have to define the type of the value that is returned by a function. For example this function header: function GetWord(string SVE_CurrentLine) should look like this: string function GetWord(string SVE_CurrentLine) Link to comment Share on other sites More sharing options...
irswat Posted November 6, 2016 Author Share Posted November 6, 2016 :-) thanks guys. that crossed my mind. that fixed it. Link to comment Share on other sites More sharing options...
Recommended Posts