Accessing contents of field on previous card SOLVED

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
calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Accessing contents of field on previous card SOLVED

Post by calmrr3 » Sat Jan 17, 2015 1:41 pm

Hello,

I can't seem to figure out how to do the following:

On opening the 2nd card I would like to be able to access the contents of a field on the previous card line by line:

Code: Select all

global counterVar
global allXCoords
global tList
global tMax
global tMin
global tList2
global tMax2
global tMin2
global pLatitude
global pLongitude
global pAltitude

on openCard
   lock screen
   repeat with itemCount = 1 to counterVar
      put line itemCount of field "latitude" into xLoc
      put line itemCount of field "longitude" into yLoc
      put (((xLoc - tMin) * (the width of this card - 1)) / (tMax - tMin)) + 1 into xLocNew
      put (((yLoc - tMin2) * (the width of this card - 1)) / (tMax2 - tMin2)) + 1 into yLocNew
      
      create grc itemCount
      set the location of grc itemCount to xLocNew,yLocNew
      set the style of grc itemCount to oval
      set the width of grc itemCount to 20
      set the height of grc itemCount  to 20
      set the opaque of grc itemCount  to true
      
   end repeat
end openCard
On the first card I have this script:

Code: Select all

global counterVar
global allXCoords
global tList
global tMax
global tMin
global tList2
global tMax2
global tMin2
global pLatitude
global pLongitude
global pAltitude
global xLocNew
global yLocNew

on locationChanged pLatitude, pLongitude, pAltitude
  put pAltitude into field "altitude"
   put pLatitude & cr after field "latitude"
   put pLongitude & cr after field "longitude"
   put counterVar into field "counter"
   add 1 to counterVar
   put counterVar into field "counter"
end locationChanged  pLatitude, pLongitude, pAltitude


on findMinMaxLat
   put fld "Latitude" into tList
   replace cr with comma in tList
   put max(tList) into tMax
   put min(tList) into tMin
   answer "MaxX: " & tMax & cr & "MinX: " & tMin
end findMinMaxLat


on findMinMaxLon
   put fld "Longitude" into tList2
   replace cr with comma in tList2
   put max(tList2) into tMax2
   put min(tList2) into tMin2
   answer "MaxY: " & tMax2 & cr & "MinY: " & tMin2
end findMinMaxLon


on errorDialog pExecutionError, pParseError
   answer "An error occurred on line: " & item 2 of line 1 of pExecutionError & cr & pExecutionError
end errorDialog
What this script is doing: Each time the location changes it adds the new latitude and longitude coordinates into two separate fields thus creating a list of the latitude coordinates and a list of the longitude coordinates - both in the order in which they were visited.

The objective of the second card script is to go through the values line of the fields (on the previous card) line by line (ie setting the location of the circle to:

'line one of field latitude','line one of field longitude'

then creating another circle at:

'line two of field latitude','line two of field longitude'

and so on.. )

Because the latitude and longitude values don't match the size of the card I have used:

Code: Select all

NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin
To remap the values to the scale of the card.
Last edited by calmrr3 on Sat Jan 17, 2015 2:22 pm, edited 1 time in total.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Accessing contents of field on previous card

Post by dave.kilroy » Sat Jan 17, 2015 1:59 pm

Hi calmrr3 - in the script of your second card try this:

Code: Select all

     put line itemCount of field "latitude" of card 1 into xLoc
"...this is not the code you are looking for..."

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Accessing contents of field on previous card

Post by calmrr3 » Sat Jan 17, 2015 2:22 pm

Thank you! I never thought it would be that simple!

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

Re: Accessing contents of field on previous card SOLVED

Post by Klaus » Sat Jan 17, 2015 2:28 pm

For speed do NOT access fields line by line!
Put the complete text of a field into a variable and use that variable, this will be thousand times faster! :D

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Accessing contents of field on previous card SOLVED

Post by dave.kilroy » Sat Jan 17, 2015 2:43 pm

yep Klaus is quite right - you might also consider whether you need so many globals...
"...this is not the code you are looking for..."

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Accessing contents of field on previous card SOLVED

Post by calmrr3 » Sun Jan 25, 2015 4:38 pm

Klaus wrote:For speed do NOT access fields line by line!
Put the complete text of a field into a variable and use that variable, this will be thousand times faster! :D
So if i said

Code: Select all

put fld "nameOfField" into fieldVariable
would I be able to access the contents of the variable in the same way as I would if it was a field? ie:

Code: Select all

put line itemCount of fieldVariable into xLoc
Thanks

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Accessing contents of field on previous card SOLVED

Post by dave.kilroy » Sun Jan 25, 2015 4:49 pm

Yep, you've got it exactly right :)
"...this is not the code you are looking for..."

Post Reply