3

I have stored a stack in a custom property, using

set the cStack of stack "abc" to \
  url "binfile:~/desktop.abc.rev"

This opens the stack:

go inv stack (the cStack of this stack)

The stack needs to be hidden. Due to the nature of the project, I can't know the name of the stack in advance, but I need to know its name to use it. I tried to use the openStacks, because I thought that the last opened stack would appear at the top of the list, but that doesn't work. I also tried the stacks but that doesn't even contain the name of the stack. The last stack causes an error.

How can I get the name of the most recently opened stack?

2 Answers2

1

You could do the following:

put the openstacks into tOpenStacksBefore

go inv stack (the cStack of this stack)

repeat for each line tStack in the openStacks
   if tStack is not among the lines of the openstacks then 
      exit repeat
   end if
end repeat

-- tStack now contains the name of your stack

Basically you are:

  1. Storing a list of open stacks before you open yours.
  2. Repeating for each of the openstacks to find the one that wasn't in the list before you opened your stack.
Benjamin Beaumont
  • 910
  • 1
  • 6
  • 14
  • I should say that I don't think there is a way in LiveCode to get the "last stack". You can get the "last control" to get the ID of the control that was last created but it's a little different with stacks. – Benjamin Beaumont Jul 17 '14 at 17:06
  • Thanks. It is a nice solution but apparently I can also get the long id directly using `this stack`. –  Jul 17 '14 at 21:01
0

Right after you open the stack, you can get the long id of this stack. That allows you to refer to it later.

go inv stack (the cStack of this stack)
put the result into rslt
if rslt is empty then put the long id of this stack into myStack
else put empty into myStack
// example
put fld 1 of myStack into myData
Mark
  • 2,380
  • 11
  • 29
  • 49