Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with Director .. reading intxt files and report print

Status
Not open for further replies.

roytheboy

Programmer
Aug 18, 2002
58
0
0
GB
Hey peeps.

I really need help with

reading a txt file into director to populate tickboxes and text boxes. I have had this working before but on a director machine only ... would not work on another.

@@@@@@@@@

I'm building a director application that runs as a standalone projector that has a lot of radiobuttons and checkboxes in. I have to be able to save these selections to a text file and for when the user revisted their previous selections are already selected!

I've managed to create a string with all the values of the selections in that looks something like this:

q1radio = YES
q2radio = NO
q3radio = NO
q1check = 0
q2check = 1
q3check = 0
q4radio = YES
q5radio = NO
q6radio = NO
q4check = 0
q5check = 0
q6check = 1

and once the string is complete I write it to text file using this:

setPref(VarNameofUser,mytextstring)

This all works fine! The problem is that when I use GetPref to retrieve the text file I don't know how to use the info to check/uncheck the relevent radio buttons. On another forum I have been suggested to split the string into an array. But I must be doing something wrong as I can't get it to work!

Has anyone got any suggestions?

@@@@@
another thing

@@@@@

I've got a movie with a print button that when its clicked I need it to print what on the screen on frames 20-25.

Looking at the Director Documnetation I think the PrintFrom method is capeable of doing this, but I can't get it to work.

OR

someone please suggest a way that I could get a printed report from these frames with dynamic content (I'm reading information from a text file)

Please help peeps... REALLY REALLY URGENT

THanks

R
 
i can retrieve that be using get pref...

i can put info into the string

its then using that string to populate all my tick boxes and text boxes.

thanks

r
 
q1radio = YES
q2radio = NO
q3radio = NO
q1check = 0
q2check = 1
q3check = 0
q4radio = YES
q5radio = NO
q6radio = NO
q4check = 0
q5check = 0
q6check = 1

as above. someone said i may need to split the string into useable variables. I want to change the controls to give tick and untick etc....

please help.

R
 
I would convert it to a Property List (similar to Object Literal in Flash) so that you can access the data easily.

The following Lingo will read Pref file and convert the data into a Property List.
Code:
on startMovie
  data = getPref("some user")
  global gPrefList
  gPrefList = processData(data)
end startMovie

on processData(data)
  pl = [:]
  lineCnt = data.line.count
  repeat with i = 1 to lineCnt
    currentLine = data.line[i]
    pl.addProp(currentLine.word[1], currentLine.word[3])
  end repeat
  return pl
end processData
Once done, you can access to the data like this:

put gPrefList.q4radio
put gPrefList.q5check

-- "YES"
-- "0"

Let me know if this makes sense to you.

Kenneth Kawamoto
 
Hi thanks for that.

I think I understand how the main bit of code works.

But it might be a stupid question but how do I use the

put gPrefList.q4radio bit.

For example I've got a textinput on the stage called "q4radio"... how would I then extract the value of q4radio from the text file and use it to populate the textinput box? I will need to do this for check boxes and radio buttons as well, but if I can get it to work for the text input boxes I should hopefully be able to get the others working.

Thanks again
 
Thanks again, but when I try that it comes up with an error saying:

Script Error: Variable used before assigned a value
if gPrefList.?q4radio = "yes" then

 
Hi, I'm working on this project with roytheboy.

We did what you suggested, but when we try to run it comes up with an error saying its expecting a string

Thanks

Phil
 
Actually, I've managed to get it to read in all the variables now. And from that I've maanaged to populate text areas with the relevent data.

The problem is that I've got these custom Radio buttons that use image swaps and I need to activate the relevent radio buttons depending on the variables from the save file and I can't get it to work.

If you wouldn't mind having a look I could send you the code for the radio buttons
 
siestamedia is working with me FYI.

hes the one doing the real work :)

thanks

R
 
This is the radio buttons behaviour code

Code:
property radiobuttons

property selected,iselected,my,id,g,groupname,name
property originalInk,invertOnClick
property shownerror

on beginsprite me
  
  g = me.script
  
  my = sprite(me.spritenum)
  
  if name="" then
    if the runmode contains "author" then
      alert("Name not set for radio button"&return&"(frame "&the frame&" sprite "&me.spritenum&")")
    end if
    name = "undefined"
  end if
  
  originalInk = my.ink
  
  if not listp(g.radiobuttons) then
    g.radiobuttons = []
  end if
  
  selected = iselected
  
  alreadyRegistered = false
  rbn = 0
  repeat with rb in g.radiobuttons
    rbn = rbn + 1
    if rb.name = name and rb.groupname = groupname then
      alreadyRegistered = true
      g.radiobuttons[rbn].selected = selected
      g.radiobuttons[rbn].isdefault = iselected
    end if
  end repeat
  
  if not alreadyRegistered then
    add g.radiobuttons,[name:name,selected:selected,groupname:groupname,sprite:me.spritenum,isdefault:iselected]
  end if
  
  me.update()
  
end

on get me,tname
  
  tname = string(tname)
  
  g = me.script
  
  if listp(g.radiobuttons) then
    
    -- Check for group names first.
    -- The name of the selected button is returned, if group is found.
    repeat with rb in g.radiobuttons
      if rb.groupname = tname then
        if rb.selected then
          return rb.name
        end if
      end if
    end repeat
    
    -- Radio button group not found - now we check through individual button names
    -- True or false is returned if button is found
    repeat with rb in g.radiobuttons
      if rb.name = tname then
        return rb.selected
      end if
    end repeat
    
    
    
    if the runmode contains "author" then
      RETURN ""
      halt
    end if
    
    -- return default selection for this group
    repeat with rb in g.radiobuttons
      if rb.groupname = tname then
        if rb.isdefault then
          return rb.name
        end if
      end if
    end repeat
    
    
  else
    
    
    if the runmode contains "author" then
      alert("Radio Button Error:"&return&return&"'"&tname&"' not found."&return&return&"No radio buttons have been initialised.")
      halt
    end if
    
  end if
  
end if


end


on update me,sn,tstate,invertOnClick

if voidp(sn) then
my.member = member("radio button "&(["unselected","selected"][selected+1]))
else
sprite(sn).member = member("radio button "&(["unselected","selected"][tstate+1]))
end if

end


on mouseup me

selected = 1
my.member = member("radio button "&(["unselected","selected"][selected+1]))
my.ink = originalInk

repeat with rb in g.radiobuttons

if rb.groupname = groupname then
if rb.name<>name then

rb.selected = 0

me.update(rb.sprite,rb.selected)
else
rb.selected = 1
me.update()
end if
end if

end repeat


end

on mousedown me
if invertOnClick then
my.ink = 4
end if
end

on mouseupoutside me
if invertOnClick then
my.ink = originalInk
end if
end

on mouseleave me
if invertOnClick then
my.ink = originalInk
end if
end




on getPropertyDescriptionList me 

description = [:]

addProp description,#groupname, [#default:"", #format:#string, #comment:"Name of Button Group:"]
addProp description,#name, [#default:"", #format:#string, #comment:"Name of This Option:"]
addProp description,#iselected, [#default:0, #format:#boolean, #comment:"Initial State:"]
addProp description,#invertOnClick, [#default:1, #format:#boolean, #comment:"Invert On Click:"]

return description

end




on mystopmovie

script("radiobuttons").radiobuttons = void

end
 
And I've got all the relevent radio button values stored in my text file (that I can now retrieve)

 
The script to make radio button selected is in "on mouseUp" handler. If you turn that into a function, then you can call that function to make the radio selected from elsewhere in the script. Call that function from "on beginSprite" handler if the radio is selected acording to the pref file value.

Hope this makes sense!

Kenneth Kawamoto
 
Thanks Kenneth,

So do you mean in that code add another bit of code that has the same elements as the "on mouseUp" but make it a function?

e.g.

Code:
on selectRad myVal
  
  selected = myVal
  my.member = member("radio button "&(["unselected","selected"][selected+1]))
  my.ink = originalInk
  
  repeat with rb in g.radiobuttons
    
    if rb.groupname = groupname then
      if rb.name<>name then
        
        rb.selected = 0
        
        me.update(rb.sprite,rb.selected)
      else
        rb.selected = 1
        me.update()
      end if
    end if
    
  end repeat
  
  
end

Then from my sprite script I pass the value to myVal (1 for selected and 0 for not selected)
 
Yes - you don't need two of the same code though.

on mouseUp me
selectRad(1)
end mouseUp

Then you can call selectRad() from "on beginSprite": if this radio is meant to be selected then selectRad()

Something along that line.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top