What does "this" mean?

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
sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

What does "this" mean?

Post by sritcp » Sun Oct 07, 2012 6:05 pm

I have a programStack and a dataStack.
The openStack handler of the programStack loads the dataStack with

Code: Select all

go stack "dataStack"
which makes dataStack the topStack.
Now, if the next statement refers to "this stack", does it refer to the programStack (where the script is running) or the dataStack?

Anyhow, to prevent confusion, I inserted the statement

Code: Select all

go stack "programStack"
before referring to "this stack"

When I start LC and load programStack, the dataStack continues to remain on top.
If I run "openStack" again (from messageBox), then the programStack comes up on top.
Am I right in understanding that "go stack" will also make a stack the topStack?

Thanks for your patience with me,
Sri.

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

Re: What does "this" mean?

Post by Klaus » Sun Oct 07, 2012 6:26 pm

sritcp wrote:Am I right in understanding that "go stack" will also make a stack the topStack?
Yes.

As for THIS, why not simply add this in the "places in doubt":
...
answer the short name of THIS stack
...
so you can SEE what is going on?

Seeing is believing and surely better than any explanation from other people! 8)

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: What does "this" mean?

Post by sritcp » Sun Oct 07, 2012 6:48 pm

Klaus,
Yes, I saw and I believed! :D "this" does not refer to the script owner stack but the topStack.

The second part of my question still remains.
The

Code: Select all

go stack "programStack"
doesn't take effect when I start up LC. The dataStack stays on top.
It does take effect when I send openCard message again.
The difference seems to be that, when it is first loaded, the dataStack has to run its openStack (which is empty) handler
while the second time, this is not so.

I hope my description is not muddled.

Thanks,
Sri.

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

Re: What does "this" mean?

Post by Klaus » Sun Oct 07, 2012 7:02 pm

Hi sri.

need a bit more info.

When and where did you script: go stack "programStack"?
What is the main stack, what the substack?
Or are these two mainstacks?


Best

Klaus

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: What does "this" mean?

Post by sritcp » Sun Oct 07, 2012 7:29 pm

Both programStack and dataStack are mainstacks.
I start LC and load programStack.
The openStack handler of programStack has these:

Code: Select all

on openStack
some statements A,B,C.......
.....
go stack URL tFilePath -- tFilePath points to dataStack
go stack "programStack"
answer the name of this stack -- here it returns "programStack"
answer "The top stack is: " & the topStack
#THE ABOVE RETURNS "dataStack" when the program starts and the openStack handler of programStack runs for the first time
#BUT RETURNS "programStack" when the message openStack is sent to programStack a second time via the messageBox
....
some statements D,E,F...... -- these run correctly in both cases
end openStack
In other words, the "go stack" message does not make the programStack the topstack the first time (i.e., when the program starts up).
I have run this a number of ways to make it work, but the result is the same.

Thanks,
Sri.

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

Re: What does "this" mean?

Post by Klaus » Sun Oct 07, 2012 8:50 pm

Hi Sri,

aha, this happens in a standalone, right?
And "load programmstack" means via Internet?

In that case the problem is that the Rev Libraries (like the internet stuff) is not yet loaded "on openstack"!
Add a little delay and all should work fine:

Code: Select all

on openStack
  send "domystuff" to me in 1
end openStack

command domystuff
  some statements A,B,C.......
  .....
  go stack URL tFilePath -- tFilePath points to dataStack
  go stack "programStack"
  answer the name of this stack -- here it returns "programStack"
  answer "The top stack is: " & the topStack
  #THE ABOVE RETURNS "dataStack" when the program starts and the openStack handler of programStack runs for the first time
  #BUT RETURNS "programStack" when the message openStack is sent to programStack a second time via the messageBox
  ....
  some statements D,E,F...... -- these run correctly in both cases
end domystuff
Or only "outsource" the "go URL..." part.

I hope I understood this correctly... 8)

Best

Klaus

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: What does "this" mean?

Post by sritcp » Sun Oct 07, 2012 10:15 pm

Hi Klaus:

No, I am still testing it on the Mac, starting LC and opening the stacks (not even standalone).
Sorry I didn't state it explicitly.

Sri.

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

Re: What does "this" mean?

Post by Klaus » Mon Oct 08, 2012 10:28 am

Hmmm...

Try to make that stack the topstack via script:

Code: Select all

 ...
  go stack URL tFilePath -- tFilePath points to dataStack
  go stack "programStack"
  set the defaultstack to "programStack"
...

Post Reply