WriteTable -- write a table to a file (V4.0)
WriteTable(id, table[, txtmode, nobrk])
This function writes the Hollywood table specified by table to the file specified by id at the current file cursor position which you can modify by using the Seek() command.

You can load saved tables into other projects by using the ReadTable() command. The optional argument txtmode specifies whether or not the table shall be written to the file as binary data or as text. The latter is useful for embedding Hollywood tables in human readable text files, for instance XML files. In case you enable text mode, WriteTable() will automatically insert a line break after every 72 characters for better readability. If you don't want that, set the optional argument nobrk to True. In that case, no line breaks will be inserted.

This function is fully recursive. Your table can contain as many sub tables as you need. Additionally, the table can also contain Hollywood functions. See below for an example.

file to write to
table to write to the file
optional: True to write the table in human readable text or False to write plain binary data (defaults to False)
optional: True if you don't want to have line breaks inserted when in text mode (defaults to False); this argument is ignored in binary mode (V6.1)
mytable = {1, 2, 3, 4, 5,
  "Hello World",
  x = 100, y = 150,
  subtable = {10, 9, 8, 7},
  mulfunc = Function(a, b) Return(a*b) EndFunction

OpenFile(1, "table.bin", #MODE_WRITE)
WriteTable(1, mytable)

OpenFile(1, "table.bin", #MODE_READ)
newtable = ReadTable(1)

Print(newtable[0], newtable[5], newtable.x, newtable.y,
      newtable.subtable[0], newtable.mulfunc(9, 9))
The code above writes the table mytable to file "table.bin". After that, it opens file "table.bin" again and reads the table back into Hollywood. The imported table will be stored in the variable newtable. Finally, we will access the newly imported table and print some of its data to the screen. The output of the code above will be "1 Hello World 100 150 10 81".

Show TOC