Home   Help Search Login Register  

Author Topic: loadfile syntax  (Read 766 times)

0 Members and 1 Guest are viewing this topic.

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
loadfile syntax
« on: 14 Nov 2005, 01:58:38 »
BTW, if you are going to be displaying lots of text (which it looks like you are), then you might find it easiest to put that text in an external .txt file, and then use the 'loadfile' command to put its contents into the dialog. Again, just speaking from experience.

This intrigued me, and i'm curious as to how this works. I checked the comref, and it's a little wanting of examples.  ::)

Quote
loadFile filename

Operand types:
filename: String
Type of returned value:
String
Description:
Return content of given file.

Example:
loadFile "myFunction.sqf"



Do i just store that to a variable, like a global var? i.e.
Code: [Select]
TYG_MYVAR = loadFile "myText.txt"?
« Last Edit: 14 Nov 2005, 01:59:14 by Tyger »
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:loadfile syntax
« Reply #1 on: 14 Nov 2005, 08:45:07 »
The loadfile command returns a string. This string contains whatever was in the file that you loaded. Normally the command is used to load a function into a variable, but it could come in handy any time you need to load any text into OFP.

Keep in mind that functions are just strings, no different from any other. The only difference between the 'loadfile' and 'preprocessfile' commands is that 'preprocessfile' will NOT load the comments from the file (indicated by // or /* */).

So, let's say you have a dialog. You could use the ctrlsettext + loadfile commands, and display a text file to a control:

ctrlsettext [1, loadfile "stuff.txt"]

Or you could store "stuff.txt" into a variable, in case you needed to use it more than once:

_text = loadfile "stuff.txt"
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:loadfile syntax
« Reply #2 on: 14 Nov 2005, 23:46:53 »
Thank you kind sir, for the helpful information. If you could also add that to the comref that would be excellent. ;)

I'll solve this in a day or two.
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08