setting the defaultPath with dynamic values

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ThomasBodetti
Posts: 16
Joined: Tue May 14, 2013 12:30 pm

setting the defaultPath with dynamic values

Post by ThomasBodetti » Wed Aug 28, 2013 5:28 pm

I have a need to open a specific folder path, looking in the dictionary I could not find an exact example of how this should appear.

There are examples of different uses, but none that explain the defaultPath method, at least from what I read.
source dictionary
answer file "Select a file to delete:"
answer files "Select the files you wish to process:"
answer file "Input:" with "/Macintosh HD/"
answer file (field "Prompt") with type "LiveCode Stacks|rev|RSTK"
answer files "Select the images you wish to view:" with type "JPEG Images|jpg|JPEG" \

I tried several methods but they all result in the same default path.

Code: Select all

on mouseUp
    local tStartDirectory
    get tDirectory  //tDirectory is set as a global
    put it into tStartDirectory
    answer file "Select a file" with tStartDirectory
end mouseUp
What happens is the standard dialog does not appear, as expected but appears as the default path which is users desktop.

So for example the user has to navigate, this way, desktop,user,folder1,folder2,file,

Are there any other methods of setting the defaultPath where I could can open a folder in a set location without having the user to navigate through several layers of folders and paths each time?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: setting the defaultPath with dynamic values

Post by Klaus » Wed Aug 28, 2013 5:39 pm

Hi Thomas,

you need to declare the global everytime you use it!

Code: Select all

on mouseUp
    global tDirectory
    answer file "Select a file" with tDirectory
    ## No need to use any other variable! ;-)
end mouseUp
Works here! :D

If in douct, let you "answer tDirectory" to check the path.


Best

Klaus

ThomasBodetti
Posts: 16
Joined: Tue May 14, 2013 12:30 pm

Re: setting the defaultPath with dynamic values

Post by ThomasBodetti » Wed Aug 28, 2013 7:38 pm

Yes, I did get it to work, only I think I did not completely understand how to set a global or define its value,

I must have not correctly set the global to the folder path, I set what I would call in PHP a super global, $mypathtofile
loaded that into a variable then it did work, so far nothing else I have tried has returned a value at all.

I even tried the message watcher, but I think it cannot see path the IDE so something was not sending back the values,

How would you set a global value, could it be done in a on preOpenCard (I think not because I already tried that)

I think from reading the dictionary that the global only works on each card?

So declaring it in the card script does not make it a global outside that area, hmmm, I think I almost have this figured out, I think the super global, (I dont think that is right but it sticks in my head like a fish hook.) is not the proper method of declaring a value between cards and or handlers.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: setting the defaultPath with dynamic values

Post by Klaus » Wed Aug 28, 2013 8:33 pm

Hi Thomas,

well, GLOBAL means GLOBAL, means a global variable is available
in every stack/card/object if declared correctly! :D

You need to declare it in every script or handler like this:

Code: Select all

## Card script:

## Put it on top of the script so you do not need to declare it in every handler!
global tGlobVar

on open card
  put 10 into tGlobVar
end opencard

command myhandler
   answer tGlobVar
end myhandler

## etc...

Code: Select all

## Object script (button orwhatever)
## Only one handler, so we need to declare it:
on mouseup
  global tGlobVar
  add 29 to tGlobVar
end mouseup
Etc. you get the picture :D


Best

Klaus

ThomasBodetti
Posts: 16
Joined: Tue May 14, 2013 12:30 pm

Re: setting the defaultPath with dynamic values

Post by ThomasBodetti » Wed Aug 28, 2013 8:42 pm

Oh, yes, now I see, you put it, I was trying to set the global

Thank you very much.

Post Reply