how to determine the stack an object belongs to
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
how to determine the stack an object belongs to
Hello!
I have a really silly question: how do I determine the (name of) a stack a given object belongs to?
Let's say, the object is "the target" of a message. If I look at "the long name of the target", the name of the stack is part of it. But how do I robustly extract the stack name?
At first, one could think of
set the wholeMatches to true
local TargetName; put the long name of the target into TargetName
word (WordOffset("stack",TargetName)+1) of TargetName
which works in many situations, but not all (e.g., if the object is placed on a card named ' "stack" ' (where the single quotes mark begin and end of the name), the abovementioned lines fail miserably...)
Is there a better (i.e., more direct) approach?
Thanks in advance for any help!
I have a really silly question: how do I determine the (name of) a stack a given object belongs to?
Let's say, the object is "the target" of a message. If I look at "the long name of the target", the name of the stack is part of it. But how do I robustly extract the stack name?
At first, one could think of
set the wholeMatches to true
local TargetName; put the long name of the target into TargetName
word (WordOffset("stack",TargetName)+1) of TargetName
which works in many situations, but not all (e.g., if the object is placed on a card named ' "stack" ' (where the single quotes mark begin and end of the name), the abovementioned lines fail miserably...)
Is there a better (i.e., more direct) approach?
Thanks in advance for any help!
Kind regards,
Andreas Rozek
Andreas Rozek
By the way,
it might be really interesting to try the example I gave in my posting - for an object which is placed on a card of a substack of a mainstack.
The result was quite unexpected - for me, at least.
EDIT: well, and if you want to disturb Revolution even more, try to give the card a name which contains a single double-quote (or, perhaps, an odd number of them in general).
it might be really interesting to try the example I gave in my posting - for an object which is placed on a card of a substack of a mainstack.
The result was quite unexpected - for me, at least.
EDIT: well, and if you want to disturb Revolution even more, try to give the card a name which contains a single double-quote (or, perhaps, an odd number of them in general).
Last edited by rozek on Wed Jun 18, 2008 1:42 pm, edited 1 time in total.
Kind regards,
Andreas Rozek
Andreas Rozek
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
You are pretty much left to parsing the object reference yourself. If you use the long id of an object rather than the long name then you don't need to worry about "stack" appearing in the name of a control.
And here is a CardOf function as well:
Code: Select all
function StackOf pControl
local theCharNo
put the long id of pControl into pControl ## force the long id
if word 1 of pControl is not "stack" then
put offset(" of stack ", pControl) into theCharNo
if theCharNo > 0 then
delete char 1 to (theCharNo + 3) of pControl
else
put empty into pControl
end if
end if
return pControl
end StackOf
Code: Select all
function CardOf pControl
local theCharNo
put the long id of pControl into pControl ## force the long id
if word 1 of pControl is not "card" then
put offset(" of card ", pControl) into theCharNo
if theCharNo > 0 then
delete char 1 to (theCharNo + 3) of pControl
else
put empty into pControl
end if
end if
return pControl
end CardOf
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Hihi,
I just wanted to test what happes, if the name of a substack contains spaces and a single double quote...and what happened?
The "stack inspector" no longer comes up - seems that I have found a bug in the IDE
So, don't try that yourself or you'll have to rename your stack using Transcript!
I just wanted to test what happes, if the name of a substack contains spaces and a single double quote...and what happened?
The "stack inspector" no longer comes up - seems that I have found a bug in the IDE

So, don't try that yourself or you'll have to rename your stack using Transcript!
Kind regards,
Andreas Rozek
Andreas Rozek
Trevor,
I just looked through your example code: in "StackOf" you explicitly check for a stack reference - but what happens, if you pass such a stack reference to "CardOf" (and choose a stack name which contains " of card ")? Shouldn't you explicitly check for stack references in "CardOf" as well (just to make your code robust)?
I just looked through your example code: in "StackOf" you explicitly check for a stack reference - but what happens, if you pass such a stack reference to "CardOf" (and choose a stack name which contains " of card ")? Shouldn't you explicitly check for stack references in "CardOf" as well (just to make your code robust)?
Kind regards,
Andreas Rozek
Andreas Rozek
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Sure. Here is some updated code:
Code: Select all
function CardOf pControl
local theCharNo
put the long id of pControl into pControl ## force the long id
if word 1 of pControl is "stack" then
put empty into pControl -- has no card
else
if word 1 of pControl is not "card" then
put offset(" of card ", pControl) into theCharNo
if theCharNo > 0 then
delete char 1 to (theCharNo + 3) of pControl
else
put empty into pControl
end if
end if
end if
return pControl
end CardOf
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder