[Closed] Rollout, using external files on load
Hi,
I’m having this problem. I want my script to load some outside variables on start. Usually I would use
on Script open do (
filein @"my_file"
)
But since on rollout creation first are created all the buttons, the command “on open do…” is always executed after.
I have also tried to just put the line
filein @"my_file"
at start, before buttons, but this errors out.
So how can I call some exteral file before button creation?
rollout dialog ""
(
local data_file = @"c: emp\data.txt"
local data =
(
if doesfileexist data_file do filein data_file
)
button bt "Button"
on dialog open do ()
)
createdialog dialog
What if my wanted to use some variables like that:
rollout dialog ""
(
local data_file = @"c: emp\data.txt"
local data =
(
if doesfileexist data_file do filein data_file
)
dropdownlist list items:my_array
on dialog open do ()
)
createdialog dialog
a the file would be:
my_array = #()
my_array[1] = "one"
my_array[2] = "two"
my_array[3] = "three"
obviously this errors out. But this is kind of structure I’m looking for
there are many ways to do it… all depends of type of data you want to store.
in your case it might be as:
rollout dialog ""
(
local data_file = @"c: emp est.txt"
fn readDataFile file: =
(
local data
if file == unsupplied do file = data_file
ss = openfile file
if ss != undefined do
(
data = execute (readline ss)
close ss
)
data
)
local my_array =
(
readDataFile()
)
button bt "Button"
on bt pressed do format ">> %
" my_array
on dialog open do ()
)
createdialog dialog
where content of @“c: emp est.txt” file is:
#("one", "two", "three")
the idea is to load a data from a file somehow in local scope of rollout before this rollout controls definition.
wow, this code is awsome!
I was going to store the values in outside .txt (maybe later .xml) files, but had very hard time figuring out how writing/reading actually works