Hello everyone! I new to Revolution, coming from the web world.
I have a field on one card that is linked so it's goes to another card when clicked (go to card 2). What's a good way to pass data between the cards when the link is clicked? I'm trying emulate the way traditional web links work with GET parameters but that idea doesn't seem to translate here? Should I set a global variable when the link is clicked and access it from the destination card? Seems like there might be a better way...
On the destination card I have listmagic powered table field that will take the parameter I'm trying to pass and go to the web to fetch a bunch of JSON data to populate the table.
passing data between cards, use globals?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact:
Using a global is one way to go, but there are other options.
You might use a "send". If your data is in a variable someVar,
send "fillListFromWeb someVar" to cd 2
and in the script of cd 2, you have a handler
on fillListFromWeb pVar
One thing about this approach that can be tricky is if the 'fillListFromWeb' handler has many references local to cd 2, so you could do something like:
send "fillListFromWeb someVar" to cd 2 in 5 millisecs
go cd 2
Another approach might be to use a customProperty:
set the webData of cd 2 to someVar
go cd 2
....
and in cd 2's script
on openCard
fillListFromWeb the webData of me
end openCard
There are other ways, but those two are what occurs to me off the top of my head.
Best,
Mark
You might use a "send". If your data is in a variable someVar,
send "fillListFromWeb someVar" to cd 2
and in the script of cd 2, you have a handler
on fillListFromWeb pVar
One thing about this approach that can be tricky is if the 'fillListFromWeb' handler has many references local to cd 2, so you could do something like:
send "fillListFromWeb someVar" to cd 2 in 5 millisecs
go cd 2
Another approach might be to use a customProperty:
set the webData of cd 2 to someVar
go cd 2
....
and in cd 2's script
on openCard
fillListFromWeb the webData of me
end openCard
There are other ways, but those two are what occurs to me off the top of my head.
Best,
Mark
really cool stuff! glad to find out there a few different options. after playing around with them I decided to go with a hybrid approach. I created a custom property set on the card that has the data grid. I'm going to store the parameters that I'll use to access different types of data sets from the server "tag_id, current_page, records_retrieved" etc...
then on the card's script I created some basic getters and setters for the parameters in my custom set. That way I can call on these from anywhere and if I decide to change the way I store the params i just have to change these two functions and all the code referencing them will still work.
I'm still deciding between commands and functions for the setters and getters. Right now my setter is a command "on SetTag" and the getter is a function...
i had some trouble working with "on linkClicked pLink" in my first card. Seemed to just stop firing and I couldn't figure out why. So now I'm still setting the linkText of the field but instead of relying on "linkClicked" I'm using "on mouseUp" instead then grabbing the value of linkText and taking action from there.
then on the card's script I created some basic getters and setters for the parameters in my custom set. That way I can call on these from anywhere and if I decide to change the way I store the params i just have to change these two functions and all the code referencing them will still work.
I'm still deciding between commands and functions for the setters and getters. Right now my setter is a command "on SetTag" and the getter is a function...
i had some trouble working with "on linkClicked pLink" in my first card. Seemed to just stop firing and I couldn't figure out why. So now I'm still setting the linkText of the field but instead of relying on "linkClicked" I'm using "on mouseUp" instead then grabbing the value of linkText and taking action from there.
nimbleRev,
Plenty of possibilities. No need for globals, properties and other intermediate storage of data.
Best,
Mark
Code: Select all
-- script of cd 2
on preOpenCard
-- option 1
put fld 1 of cd 1 into fld 1 of cd 2
-- option 2
put fld 1 of cd 1 into myVar
doSomeThingWith myVar
-- et cetera
end preOpenCard
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Just to play devil's advocate here (I *never* use globals myself unless for some reason I need access to system globals), Chipp Walters once pointed out a very clever use for global variables.
Taking advantage of the fact that global variables are persistent in memory, Chipp stores a value into a global and can then close the stack he's working on, open another stack, and still have the global available. This can be handy if, for instance, you have two stacks of the same name and want to be able to paste scripts from one to the other.
Granted that it's a specialized case, but it's a clever hack.
Taking advantage of the fact that global variables are persistent in memory, Chipp stores a value into a global and can then close the stack he's working on, open another stack, and still have the global available. This can be handy if, for instance, you have two stacks of the same name and want to be able to paste scripts from one to the other.
Granted that it's a specialized case, but it's a clever hack.