Page 1 of 1
put command into global variable, possible?
Posted: Fri Feb 27, 2015 9:19 pm
by sphere
Hello,
is there a way to put a command into an gloabl variable?
I'm asking so it would be some easier to test some thing while working on in in windows.
So i heave these line added to the stack script:
Code: Select all
if the environment is "mobile" then
put "engine" into gHome
else put "documents" into gHome
if the environment is "mobile" then
put "mobilePlaySoundOnChannel" into gPlayer
else put "play"into gPlayer
And this to a button script:
Code: Select all
gPlayer specialFolderPath (gHome) &("/audio/") & ("1.wav"), "current", "now"
so the gHome is working but the gPlayer not
Livecode don't like it , and says there is no handler
but it's a global
is there any way to do something like this?
Saves a lot of time then to upload it every time to my android phone, because now it could work on windows(test) and on Android (finnaly it should be android)
thanks for any ideas on this.
sphere
Re: put command into global variable, possible?
Posted: Fri Feb 27, 2015 10:45 pm
by FourthWorld
What you're looking for is almost like closures, which would be nice to see in LiveCode but not currently supported.
One option might be to use "do", similar to JavaScript's "eval", to force LC to evaluate and execute the string as a whole:
Code: Select all
do ( gPlayer "& specialFolderPath (gHome) &(""e&"/audio/""e&") &\
(""e&"1.wav""e^"), ""e&"current""e&", ""e&"now""e)
But such dynamically modified code using "do", "value", etc. is relatively slow (minor concern), and often more difficult to debug and maintain (bigger concern).
Since you're already using "if" to branch the code, why not just take that to completion with a handler that plays audio regardless of platform, e.g.:
Code: Select all
on PlayAnywhere pFile
if the environment is "mobile" then
mobilePlaySoundOnChannel (specialFolderPath ("engine") & "/audio/" & pFile) , "current", "now"
else
put "documents" into gHome
play (specialFolderPath("documents)&"/audio/"& pFile)
end if
end PlayAnywhere
With that handler you can call it from anywhere on either platform, just passing in the short name of the audio file.
Re: put command into global variable, possible?
Posted: Wed Mar 04, 2015 12:48 pm
by sphere
Hello Richard,
sorry for not replying earlier, i forgot the check the notify me box for replies.
Thanks a lot for your input, i'm going to check tonight and let you know
Sphere
Re: put command into global variable, possible?
Posted: Fri Mar 06, 2015 12:52 pm
by sphere
It seems that this works.
next problem i have is that link to the audio file is lost when accessing the handler, whatever type of variable i use tFile,gFile,sFile or the pFile you used (i don't know why you called it pFile)
So have to do some testing with a little script why the variable is lost.
I allready found some ideas to this, but not working ones yet.
And it seems that you have to declare it before the on mousUp, so it should be available on the whole script.
Thanks!
Re: put command into global variable, possible?
Posted: Fri Mar 06, 2015 1:33 pm
by Klaus
Hi sphere,
sounds like you are doing something wrong, please post your script(s) here so we can fix it!
Actually the variable CAN NOT be lost, since it is just a parameter to the handler, if you use Richards script.
You just "call" it with the filename of the sound you want to play, like:
Code: Select all
on mouseup
PlayAnywhere "great_sound_file.mp3"
end mouseup
And the handler "PlayAnywhere" will take care of all the rest.
Best
Klaus
Re: put command into global variable, possible?
Posted: Fri Mar 06, 2015 8:41 pm
by sphere
Hi Klaus,
i found what i did wrong.
the specialfolderpath was in the mouseUp part, but also in the handler part.
So in fact it was double. In the handler i only needed Play sFile.
I declared variable before the On mouseUp command so that it is available on the whole script (as i read at some places) and used the sVariable type instead of tVariable
Also i noticed that putting the variable name behind the - on handlername like : on handlername sVariable seems to block the variable, and just on handlername does not
---When it is ready i will make it public, until then i keep on working on it. Because it is for a very special young lady. And then i can also tell you why she is special, just as a friend. and possibly the idea is allready out there. I just wait untill before spreading it. But i think she will be very delighted when it is working on her Android phone

And then it is also interesting for other people.
Re: put command into global variable, possible?
Posted: Mon Mar 16, 2015 7:59 pm
by sphere
Hi Klaus,
what a coincidence with Livecode 8 and autism.
As this app i was creating was for this special lady, she is family of a dear friend of mine and she has autism.
She can't read the time from a clock.
So i created the "Elles - Tijd & Datum" app for Android.
This is in dutch and it took some time to figure out how to speak it all out correctly like they do in normal dutch speach.
Because in every language it is a bit different, but i think it could be easily adjusted to any other language.
Now i only need to change the voice (cause it's my own static voice) but it works and that counts right now.
Of course it is a free app.
Any one who wants the source or the program, just send me an email or a PM
This probably could be programmed a lot more easy or better, but i succeeded and that's what counts.
I'm going to repost this i a new thread too i think.
Cheers !