locationChanged on mouseUp

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
link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

locationChanged on mouseUp

Post by link76 » Fri Apr 12, 2019 2:09 pm

Is it possible to activate the locationChanged function when the user presses a button, for example?

Currently I have inserted this function in OpenCard but in this way it is always active.

Thank you

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: locationChanged on mouseUp

Post by Klaus » Fri Apr 12, 2019 2:18 pm

I don't think so, because this is a MESSAGE and not a function.
From the dictionary:
Sent to the current card of the default stack when the location of the device changes.
So only the CARD (or stack) will receive this message, but none of your buttons or other objects.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: locationChanged on mouseUp

Post by bogs » Fri Apr 12, 2019 2:53 pm

Klaus wrote:
Fri Apr 12, 2019 2:18 pm
So only the CARD (or stack) will receive this message, but none of your buttons or other objects.
Could you not do something like this in the button/whatevers script :

Code: Select all

on mouseUp
	send locationChanged(pLat,pLong,pAlt) to card "xyz"
end mouseUp	
:?:

Alternately, you could roll your own handler for the change in location, since the above still isn't going to change the way the message works (i.e. you have to as Klaus said put the locationChanged handler in the card).
Image

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: locationChanged on mouseUp

Post by Klaus » Fri Apr 12, 2019 3:00 pm

bogs wrote:
Fri Apr 12, 2019 2:53 pm

Code: Select all

on mouseUp
	send locationChanged(pLat,pLong,pAlt) to card "xyz"
end mouseUp	
You do not know what values pLat, pLong and pAlt have at this point!

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: locationChanged on mouseUp

Post by link76 » Fri Apr 12, 2019 3:04 pm

bogs wrote:
Fri Apr 12, 2019 2:53 pm
Klaus wrote:
Fri Apr 12, 2019 2:18 pm
So only the CARD (or stack) will receive this message, but none of your buttons or other objects.
Could you not do something like this in the button/whatevers script :

Code: Select all

on mouseUp
	send locationChanged(pLat,pLong,pAlt) to card "xyz"
end mouseUp	
:?:

Alternately, you could roll your own handler for the change in location, since the above still isn't going to change the way the message works (i.e. you have to as Klaus said put the locationChanged handler in the card).
does not work, the app crashes! I would like to use the locationChanged message to trace the user but only if activated by the user. Another solution ?

Code: Select all

on mouseUp
   mobileStartTrackingSensor "location", false
   send locationChanged to this card 
end mouseUp

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: locationChanged on mouseUp

Post by Klaus » Fri Apr 12, 2019 3:28 pm

link76 wrote:
Fri Apr 12, 2019 3:04 pm

Code: Select all

on mouseUp
	send locationChanged(pLat,pLong,pAlt) to card "xyz"
end mouseUp	
does not work, the app crashes!
What did you exspect when you pass the STRINGS! "pLat", "pLong" and "pAlt" in that call? :D
If a variable is empty/not initialized, its value is its name as a string!

You cannot "fake" a message that comes from "outside" of LC, since you do not know the values of pLong etc., see above. However, starting the sensor "on mouseup" should work, but then the "locationchanged" message is still sent to the current card!

Code: Select all

on mouseUp
   mobileStartTrackingSensor "location", false
end mouseUp
You still need an appropriate "locationchanged()" handler in the card- or stack script.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: locationChanged on mouseUp

Post by bogs » Fri Apr 12, 2019 3:35 pm

link76 wrote:
Fri Apr 12, 2019 3:04 pm
does not work, the app crashes! I would like to use the locationChanged message to trace the user but only if activated by the user. Another solution ?
Klaus wrote:
Fri Apr 12, 2019 3:28 pm
You cannot "fake" a message that comes from "outside" of LC, since you do not know the values of pLong etc., see above. However, starting the sensor "on mouseup" should work, but then the "locationchanged" message is still sent to the current card!
Hum. I might as well go ahead and show my (even more complete) ignorance again, why not stick the locationChanged handler into a custom property of the card/stack, create a handler such as:

Code: Select all

on myLoc
	do the custPropMyLoc of this card
end myLoc
then from the button

Code: Select all

send myLoc to card "xyz"
:?: :?:

I also seem to remember that you could put scripts into objects, without having them there from the beginning, but (unfortunately) don't remember the details.
Image

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: locationChanged on mouseUp

Post by Klaus » Fri Apr 12, 2019 3:42 pm

Obviously I have to repeat myself:
You cannot "fake" a message that comes from "outside" of LC, since you do not know the CURRENT values of pLong etc.
Hey, mom called! What did she say?
No idea, I faked the phone call.

You get the picture... :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: locationChanged on mouseUp

Post by bogs » Fri Apr 12, 2019 4:15 pm

Actually I seem to be missing that picture (again, blatant ignorance in how stuff works on mobile). I am pretty sure I used a similar bit to shell out for information on the desktop at one point, but maybe thats different.
Image

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: locationChanged on mouseUp

Post by Klaus » Fri Apr 12, 2019 4:37 pm

This has nothing to do with "how stuff works on mobile", its pure logics!

If you receive a message (with params!) of whatever kind from OUTSIDE of LC, you do not
know what info the params may bring. So you cannot fake nor "force" this message, you can
only react WHEN the message comes in.

Read up my "mom called" example again and let it sink a bit, I'm sure you'll understand the problem.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: locationChanged on mouseUp

Post by bogs » Fri Apr 12, 2019 4:56 pm

Klaus wrote:
Fri Apr 12, 2019 4:37 pm
This has nothing to do with "how stuff works on mobile", its pure logics!
If you say so. I still don't get it myself, but that isn't really a problem as long as link76 does :D
Klaus wrote:
Fri Apr 12, 2019 4:37 pm
If you receive a message (with params!) of whatever kind from OUTSIDE of LC, you do not
know what info the params may bring
See, to me, there is a way to get those from outside and insert them, but again, that might be an error in my thinking.
Image

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: locationChanged on mouseUp

Post by Klaus » Fri Apr 12, 2019 5:19 pm

bogs wrote:
Fri Apr 12, 2019 4:56 pm
Klaus wrote:
Fri Apr 12, 2019 4:37 pm
If you receive a message (with params!) of whatever kind from OUTSIDE of LC, you do not
know what info the params may bring
See, to me, there is a way to get those from outside and insert them, but again, that might be an error in my thinking.
To use this example here, so you are fetching the current altitude, longitude and whatever values with your sextant and then pass it over to LC? :D

Again:
We cannot know the values of the parameters of the "message-to-come" BEFORE the message arrives! Agreed?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: locationChanged on mouseUp

Post by bogs » Fri Apr 12, 2019 7:45 pm

Ah, I (think) I see what your talking about, but I also think we are talking at cross purposes because I am lacking some fundamental basic understanding about programming for mobile.

On what you said in the last post, agreed, I don't think you can *fake* a message that comes from outside of Lc, I just think there is a way to get the items that make up the message and bend it to our needs. Unfortunately, what way that is is beyond me due to ignorance.
Image

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: locationChanged on mouseUp

Post by Klaus » Fri Apr 12, 2019 7:51 pm

bogs wrote:
Fri Apr 12, 2019 7:45 pm
On what you said in the last post, agreed, I don't think you can *fake* a message that comes from outside of Lc
Ah, finally, yes, that was my only point, since I only referred to this example with "locationchanged()". :D
bogs wrote:
Fri Apr 12, 2019 7:45 pm
I just think there is a way to get the items that make up the message and bend it to our needs.
Yes, sure, but just not all.

bwmilby
Posts: 439
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: locationChanged on mouseUp

Post by bwmilby » Sat Apr 13, 2019 2:42 am

What he wants is probably

Code: Select all

mobileCurrentLocation()
to get the current location. If he wants to track changes, then he would respond to the message he originally asked about. Both require the app to start tracking location as mentioned earlier in the thread. I’m not sure if enabling tracking will generate the change message initially which is why I’m suggesting this function.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”