Difference between revisions of "User:QQuix/Array sample code"
Jump to navigation
Jump to search
Added a limit to the depth of the dump
imported>QQuix m (Minor text and code changes) |
imported>QQuix (Added a limit to the depth of the dump) |
||
Line 17: | Line 17: | ||
It dumps the array to the console and to a text file (requires Pluggy), but either can be easily removed, if you prefer. It is also easy to customize the contents and formatting to your liking. | It dumps the array to the console and to a text file (requires Pluggy), but either can be easily removed, if you prefer. It is also easy to customize the contents and formatting to your liking. | ||
Optionally, you may limit the number of levels to dump. | |||
It has two modes. | It has two modes. | ||
Line 77: | Line 79: | ||
let aaqqArrayDump.isArrayName := "ObjectTree" ; set array name - for the header | let aaqqArrayDump.isArrayName := "ObjectTree" ; set array name - for the header | ||
let aaqqArrayDump.iMode := 1 ; set Mode | let aaqqArrayDump.iMode := 1 ; set Mode | ||
let aaqqArrayDump.iDepth := 3 ; Number of levels to dump (0 = All) | |||
aaqqArrayDump.activate player 1 | aaqqArrayDump.activate player 1 | ||
Line 90: | Line 93: | ||
array_var gaKeys | array_var gaKeys | ||
array_var gaArrays | array_var gaArrays | ||
short gMaxLevel | |||
ref xSelf | ref xSelf | ||
Line 116: | Line 120: | ||
short xLevel | short xLevel | ||
short xNextLevel | short xNextLevel | ||
short xMaxLevel | |||
;=== Pluggy string vars === | ;=== Pluggy string vars === | ||
Line 177: | Line 182: | ||
if xLevel == 0 | if xLevel == 0 | ||
;=== Init MaxLevel === | |||
;============== | |||
set gMaxLevel to iDepth - 1 | |||
if gMaxLevel < 0 || xMaxLevel > 5 | |||
set gMaxLevel to 5 | |||
endif | |||
;=== Print Header === | ;=== Print Header === | ||
;============== | ;============== | ||
let sLine := "===== Deep dump Mode " + ( tostring iMode ) + " - | let sLine := "===== Deep dump Mode " + ( tostring iMode ) + " - Depth= " + ( tostring gMaxLevel + 1 ) + " - Array: [" + gaKeys [0] + "] =====" | ||
printc "PrintArray>> %z " sLine | |||
setString psLine $sLine | setString psLine $sLine | ||
StringToTxtFile psFile | StringToTxtFile psFile psLine | ||
endif | endif | ||
set xMaxLevel to aaqqArrayDump.gMaxLevel | |||
;=== Setup array and key === | ;=== Setup array and key === | ||
Line 202: | Line 214: | ||
if iMode == 2 | if iMode == 2 | ||
let sLine := sKey + " = " + "#Empty#" | let sLine := sKey + " = " + "#Empty#" | ||
printc "PrintArray>> %z " sLine | |||
setString psLine $sLine | setString psLine $sLine | ||
StringToTxtFile psFile psLine | StringToTxtFile psFile psLine | ||
Line 266: | Line 278: | ||
StringToTxtFile psFile psLine | StringToTxtFile psFile psLine | ||
endif | endif | ||
if | if xLevel < xMaxLevel ; stops recursion at the last level initialized | ||
set xNextLevel to xLevel + 1 | set xNextLevel to xLevel + 1 | ||
let aaqqArrayDump.gaKeys [xNextLevel] := sKey1 | let aaqqArrayDump.gaKeys [xNextLevel] := sKey1 | ||
Line 273: | Line 285: | ||
ar_Erase aaqqArrayDump.gaKeys xNextLevel | ar_Erase aaqqArrayDump.gaKeys xNextLevel | ||
ar_Erase aaqqArrayDump.gaArrays xNextLevel | ar_Erase aaqqArrayDump.gaArrays xNextLevel | ||
elseif xLevel == xMaxLevel && iMode == 2 | |||
let sLine := sKey + "[" + sKey1 + "]" + " . . ." | |||
printc "PrintArray>> %z " sLine | |||
setString psLine $sLine | |||
StringToTxtFile psFile psLine | |||
endif | endif | ||
endif | endif |