Page 1 of 1

locationChanged on mouseUp

Posted: Fri Apr 12, 2019 2:09 pm
by link76
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

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 2:18 pm
by Klaus
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.

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 2:53 pm
by bogs
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).

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 3:00 pm
by Klaus
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!

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 3:04 pm
by link76
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

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 3:28 pm
by Klaus
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.

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 3:35 pm
by bogs
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.

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 3:42 pm
by Klaus
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

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 4:15 pm
by bogs
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.

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 4:37 pm
by Klaus
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.

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 4:56 pm
by bogs
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.

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 5:19 pm
by Klaus
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?

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 7:45 pm
by bogs
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.

Re: locationChanged on mouseUp

Posted: Fri Apr 12, 2019 7:51 pm
by Klaus
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.

Re: locationChanged on mouseUp

Posted: Sat Apr 13, 2019 2:42 am
by bwmilby
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.