put value on variable on another stack

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
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

put value on variable on another stack

Post by palanolho » Sun Aug 04, 2013 4:47 pm

Greetings everyone.

On my app, I have created a stack to store all app settings (ex, the path of the current open document ).

so, I have this setting stack with the following code

project_settings stack

Code: Select all

local projectPath1
global projectPath2
on another stack I try to set the value of these var like this:

Code: Select all

ask file "Please name your file:"
put it into projectPath1 of stack "project_settings"
put it into projectPath2
the first put (for local var) does not work. It gives me an error (execution error at line 3 (Chunk: source is not a container), char 30)
the second put (for global var) works just fine

Anyone is able to explain me what I'm doing wrong ?
should I use a function on my settings stack to set the var value instead of trying to set it directly ?

Many thanks
- Miguel

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10360
Joined: Wed May 06, 2009 2:28 pm

Re: put value on variable on another stack

Post by dunbarx » Sun Aug 04, 2013 5:01 pm

Hi.

The syntax for putting data into a variable does not permit the designation of an object like a stack. You cannot:

put someData into someVariable of stack "someStack"

Variables are not owned by objects, in other words. They are either local or global, meaning they live either locally or globally, but only in scripts.

In your project, you would declare the variables as global, and then in any script anywhere in LC, if you declare them again, their contents will be available.

Craig Newman

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: put value on variable on another stack

Post by palanolho » Sun Aug 04, 2013 5:12 pm

Thank you for your reply.

another option would be to set properties of the stack?


- Miguel

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

Re: put value on variable on another stack

Post by Klaus » Sun Aug 04, 2013 6:08 pm

Hola Miguel,

definitively yes! :-)

---
ask file "Please name your file:"
# ALWAYS check this! ;-)
if it = empty then
exit to top
end if
set the cProjectPath1 of stack "project_settings" to it
## I got used to add a little prefix -> c for a custom property
...

As long as this stack is open (visible or not) you can access the path from ANYWHERE! with:
...
put the cProjectPath1 of stack "project_settings" into tProjectPath
...


Best

Klaus

Post Reply