BlitzArrays and strings?
Blitz3D Forums/Blitz3D Beginners Area/BlitzArrays and strings?
| ||
Maybe I've done something stupid elsewhere, admittedly, my head's spinning a bit from this right ow, but in a little program I'm having trouble with a Blitz Array. Ideally, it shoiuld store a string value, but the compielr claims a variable type mismatch. here's the full code. The compiler breaks in the GetTableNameByReference function at the first line where ffpDataFile$=affpDataFiles[] Const DATA_TYPE_INVALID=0 Const DATA_TYPE_INTEGER=1 Const DATA_TYPE_FLOAT=2 Const DATA_TYPE_STRING=4 Global fnConfigFile$="Config.ini" Global dRoot$ Global dData$ Global affpDataFiles$[256] ;Hard limit imposed, Array Size must be constant. Initialise Global nRaces_Number Global nProfessions_Number Global nAbilities_Number Type DATATABLE Field sDataTable_Friendlyame$ Field nDatatable_ColumnCount% Field anTableColumn_Columns[32] End Type Type TABLECOLUMN Field tTableColumn_Datatable.DATATABLE Field nTableColumn_ReferenceNumber% Field sTableColumn_Title$ Field nTableColumn_DataType% Field tTableColumn_RowData.TABLEROWDATA End Type Type TABLEROWDATA Field tTableRowData_Datatable.DATATABLE Field nTableRowData_ReferenceNumber% Field TableRowData_DataColumn.TABLECOLUMN Field nTableColumn_DataType Field nTableRowData_Int% Field fTableRowData_Float# Field sTableRowData_String% End Type Function nGetDataTypeOfDataTableColumnHandle%(hTableColumn) Local GetColumn.TABLECOLUMN = Object.TABLECOLUMN(hTableColumn) If (GetColumn.TABLECOLUMN=Null) Then Return DATA_TYPE_INVALID Return GetColumn\nTableColumn_DataType End Function Function hGetColumnOfReferenceFromDataTableHandle%(hDataTable,nColumnReference%) Local GetTable.DATATABLE = Object.DATATABLE(hDataTable) If (GetTable.DATATABLE=Null) Then Return -1 Local nCount%=GetTable\nDatatable_ColumnCount% If (Not(nCount%)) DebugLog "Table Column reference out of range" Return -1 End If Return GetTable\anTableColumn_Columns[nColumnReference%] End Function Function hGetTableHandleFromName(sFriendlyName$) Local GetTable.DATATABLE For GetTable.DATATABLE=Each DATATABLE If (GetTable.DATATABLE<>Null) If (GetTable\sDataTable_Friendlyame=sFriendlyName) Then Return Handle(GetTable.DATATABLE) End If Next Return False End Function Function bfGetFlagFromReference%(nReference%) Return (1 Shl (nReference)) End Function Function nGetReferenceFromFlag%(nFlag) Return ((nFlag-1) ^ 0.5) End Function Function AddDataTableNameToConfigurations(sDataTableName$) If ((sDataTableName$)<>"") Local hFile=OpenFile(fnConfigFile) If (Not(hFile)) Then RuntimeError "No Configurations" SeekFile(hFile,Eof(hFile)) WriteLine(hFile,sDataTableName$) CloseFile(hFile) RefreshTableDatafileReferences End If End Function Function ClearAllTableData() Delete Each DATATABLE Delete Each TABLECOLUMN Delete Each TABLEROWDATA DebugLog "Cleared All table data" End Function Function GetTableNameByReference$(nReference%) Local ffpDataFile$=Str(affpDataFiles$[nReference%-1]) If (Not(FileType(ffpDataFile$)=1)) DebugLog "File not found "+Chr(34)+ffpDataFile$+Chr(34) Else Local hFile=ReadFile(ffpDataFile$) If (Not(hFile)) If (Not(FileType(ffpDataFile)=1)) DebugLog "Out of data "+Chr(34)+ffpDataFile$+Chr(34) Else Local sFriendlyName$=Left(Right(ffpDataFile$,Len(ffpDataFile)-(Len(dData$))),Len(Right(ffpDataFile$,Len(ffpDataFile)-(Len(dData$))))-4) Return sFriendlyName$ End If End If End If Return "" End Function Function GetTableReferenceByName%(sFriendlyName$) sFriendlyName$=Upper(sFriendlyName) Local nIterDataFiles% Local ffpDataFiles$ For nIterDataFiles%=1 To 256 ffpDataFiles=Upper(Left(affpDataFiles$[nIterDataFiles-1],Len(affpDataFiles$[nIterDataFiles-1])-Len(dData)),(Len(Right(affpDataFiles$[nIterDataFiles],Len(affpDataFiles$[nIterDataFiles-1])-Len(dData))))-4) If(ffpDataFiles$)=(sFriendlyName$) If (FileType(affpDataFiles$[nIterDataFiles%-1])=1) Then Return nIterDataFiles% DebugLog "DataFile Not found "+Chr(34)+affpDataFiles$[nIterDataFiles%-1]+Chr(34) Return False End If Next DebugLog "DataFile Not found "+Chr(34)+sFriendlyName+Chr(34) Return False End Function Function RefreshTableDatafileReferences() Local nIterReferences% For nIterReferences%=0 To 255 affpDataFiles$[nIterReferences%]="" Next Local hFile=ReadFile(fnConfigFile) Local sLine$=ReadLine(hFile) dRoot=dFixDirPath(sLine) sLine$=ReadLine(hFile) dData=dFixDirPath(sLine) Local nCount% sLine$=ReadLine(hFile) While ((Not(Eof(hFile))) And (sLine<>"")) nCount%=nCount%+1 affpDataFiles$[nCount%-1]=dData$+sLine$+".dat" sLine$=ReadLine(hFile) Wend CloseFile hFile DebugLog "Datafile references refreshed" End Function Function Initialise() If (Not(FileType(fnConfigFile$)=1)) DebugLog "No Configuration File Exists. Maybe First Run" WriteConfigs End If RefreshTableDatafileReferences End Function Function WriteConfigs() Local hFile=WriteFile(fnConfigFile$) WriteLine(hFile,SystemProperty("appdir")) WriteLine(hFile,"Data\") Local hDataDir=ReadDir(SystemProperty("appdir")+"Data\") Local fnGetDataFile$=NextFile(hDataDir) While(fnGetDataFile$)<>"" If (FileType(fnGetDataFile$)=1) fnGetDataFile=Left(fnGetDataFile$,Len(fnGetDataFile)-4) WriteLine(hFile,fnGetDataFile) fnGetDataFile$=NextFile(hDataDir) End If Wend CloseDir hDataDir CloseFile hFile End Function Function dFixDirPath$(dPath$) If (dPath$<>"") If (Right(dPath$,1)<>"\") Then dPath$=dPath$+"\" End If Return dPath$ End Function |
| ||
hi, str isn't necesary , str spects a number not a string there are no need to convert a string to a string! Juan |
| ||
Is it because you are loading a string via Str which should take a numeric variable and shunt it to a string - but the variable you are shunting is a string in the first place? Local ffpDataFile$=Str(affpDataFiles$[nReference%-1]) ie, you have to break that sucker up a bit before shunting it. EDIT: Beaten to it - sniff. |
| ||
Oh no, sorry - the Str() was what I put in just in case after it refused to compile initially. That's not the problem, though at least I appreciate the fact it wasobviously NOT a good way to try and solve the issue :) |
| ||
You should omit the $-sign after the BlitzArray name when using it. It should only be used when the BlitzArray is defined: Global test$[3] test[1] = "Hello" ;good test$[1] = "Hello" ;bad.. |
| ||
if you write the sentence pointed with out the "$" and str() function, another malicious appear:ffpDataFiles=Upper(Left(affpDataFiles$[nIterDataFiles-1],Len(affpDataFiles$[nIterDataFiles-1])-Len(dData)),(Len(Right(affpDataFiles$[nIterDataFiles],Len(affpDataFiles$[nIterDataFiles-1])-Len(dData))))-4) again, omit the "$" split it in some parts, you will see that this sentence is incorrect, Too Many parameters. Upper only needs a string, you have so many things separated by "," juan |
| ||
@Charrua : thanks, I think I was overzealous in putting that all on one line. ffpDataFile=Upper(Right$(ffpDataFile$,Len(ffpDataFile$)-Len(dData$))) ffpDataFile=Left(ffpDataFile$,Len(ffpDataFile$)-4) This neater version does the trick :) @Warner: Well spotted. That seemed to be the main cause of the trouble. I removed the $ except for the declaration line and t works :) Thank you all! |