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
-
istech
- Posts: 211
- Joined: Thu Sep 19, 2013 10:08 am
Post
by istech » Tue Feb 18, 2014 2:54 pm
Hey Livecoders,
I have run into a problem with a simple game which works fine on windows but not device."HTC One"
The game picks a random button and shows and hides it with a delay if you hit the button it adds on to a field.
The problem I am having is on a mobile device the buttons are not responding on every click and when they get pressed there is a delay or does not respond.
Is there something mobile specific I need to write in? Any help would be great. (maybe change "wait with messages to a send command?")
Code below:
Code: Select all
on startgame
if the environment is "mobile" then
put specialfolderpath("engine") & "/pop.wav" into popSound
else
set the filename of player "DesktopCHSound" to specialFolderPath("pathBase") & "pop.wav"
set alwaysBuffer of player "DesktopCHSound" to true
end if
repeat until field "Timer" is 0
put random(5) into Rnumber
put "r" & Rnumber into Rbutton
if the environment is "mobile" then
play popSound
else
play player "DesktopCHSound"
end if
show btn Rbutton
wait 0.6 seconds with messages ## Change to send?
hide btn Rbutton
end repeat
end startgame
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Tue Feb 18, 2014 10:18 pm
It's likely the player can't load the file. Also, the dictionary doesn't show the "play" command as compatible on Android.
You definitely need to use the "send" construct here. If the player can't load the file, it will try repeatedly each time through the loop and hang for several seconds until it times out. Also, "play player" isn't a valid syntax, it should be "start player" instead.
I'd use a player object for both desktop and mobile, it will keep your scripts simpler. It's a good idea to preload the player by setting the filename before the game loop starts. That way you can check the result and see if something went wrong. Once the filename is set, playback should happen without any lag.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
istech
- Posts: 211
- Joined: Thu Sep 19, 2013 10:08 am
Post
by istech » Wed Feb 19, 2014 5:28 pm
Hi there,
Thanks for the tips. Couple of things.
The Dictionary says start player is not supported/not listed as supported for android or ios.
Can you tell me the supported method for playing audio in Android if the play command is not supported?
Do you have any pointers for converting a wait to a send command - Can "send delaybutton to me in 0.7 seconds" and link it to a hide command do the trick?
Thanks.
Not much experience with "send" and the docs have not got a lot of examples any help is much appreciated.
ps. I still get a delay when playing the sound even though the filename was already set before the loop. (Livecode just too fast? for a QT player object)
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Wed Feb 19, 2014 8:26 pm
I take it back, you're right. The play command should work on Android. I'm surprised the desktop version works, the correct syntax for that is "start player". If you aren't hearing anything on Android then all I can think of is that your Android device doesn't support that particular sound type, which is unlikely with a .wav file, or there is something not right with the file path.
If you want to preload the sound on mobile, then probably you'd want to use playSoundOnChannel with the "next" parameter, which keeps it in memory. Then whenever you need the sound you can playSoundOnChannel "now".
The "send" syntax should be used whenever possible when you have a repeat loop.
Code: Select all
on startGame
-- do start stuff
send "doGameStuff" to me in .6 seconds -- adjust as needed
end startGame
on doGameStuff
if fld "timer" > 0 then
hide btn Rbutton
put random(5) into Rnumber
put "r" & Rnumber into Rbutton
if the environment is "mobile" then
play popSound
else
start player "DesktopCHSound"
end if
show btn Rbutton
send "doGameStuff" to me in 0.6 seconds
end if
end doGameStuff
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
istech
- Posts: 211
- Joined: Thu Sep 19, 2013 10:08 am
Post
by istech » Thu Feb 20, 2014 12:20 pm
Many thanks Jacque, I will give it a go today and see what happens.
Again thanks for pointing me in the right direction. Have a cold one on me..
"Wait with messages" I shall try not to use in future unless absolutely necessary.
-
Klaus
- Posts: 14205
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Feb 20, 2014 2:08 pm
Hi istech,
will you reveal to us what -> specialFolderPath("pathBase") is?
Thank you!
Best
Klaus
-
istech
- Posts: 211
- Joined: Thu Sep 19, 2013 10:08 am
Post
by istech » Thu Feb 20, 2014 11:40 pm
Oh, do you mean the stack-tasic function the LC gurus came up with that I use in every stack from now on.
Sure
Code: Select all
function pathBase
set the itemdel to "/"
if the environment is "mobile" then return specialfolderpath ("engine")
else return item 1 to -2 of the filename of this stack
end pathBase
Now by default your wondering why I need to have the separating "if" for the environment....Maybe?
Answer? I have not got around to changing it yet.

-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Fri Feb 21, 2014 8:10 pm
The way your handler is written, "pathbase" will never return anything meaningful. The specialFolderPath function is a built-in engine function that only works with the specified locations listed in the dictionary. Pathbase isn't one of those.
What you want is:
set the filename of player "DesktopCHSound" to pathBase() & "/pop.wav"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
istech
- Posts: 211
- Joined: Thu Sep 19, 2013 10:08 am
Post
by istech » Fri Feb 28, 2014 12:00 pm
Thanks Jacque
Your right it would work in ide but not complied/standalone until I updated the code thanks.
-
Klaus
- Posts: 14205
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Feb 28, 2014 2:16 pm
istech wrote:Oh, do you mean the stack-tasic function the LC gurus came up with that I use in every stack from now on.
Sure
Code: Select all
function pathBase
set the itemdel to "/"
if the environment is "mobile" then return specialfolderpath ("engine")
else return item 1 to -2 of the filename of this stack
end pathBase
Now by default your wondering why I need to have the separating "if" for the environment....Maybe?
No, I was just wondering why you were trying to wrap a custom function (without the neccessary parens!) inside of a very special LC function
And I am even more wondering that his has been working in the IDE without any error!?
But to my surpise, putting this into the message box: put specialfolderpath("pathbase")
Gives me: /Users/klaus/Library/Application Support
So maybe you should check this (your) folder for unexspected files

-
istech
- Posts: 211
- Joined: Thu Sep 19, 2013 10:08 am
Post
by istech » Thu Mar 06, 2014 3:30 pm
Yes very interesting Klaus,
However I never got any errors and no extra files. Maybe I got lucky

-
Klaus
- Posts: 14205
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Mar 06, 2014 3:35 pm
Too funky!
Oh, I just noticed my number of postings
OK, here's to you and me:

-
istech
- Posts: 211
- Joined: Thu Sep 19, 2013 10:08 am
Post
by istech » Thu Mar 06, 2014 4:03 pm
Cheers

you will be at 6666 in no time. Is that lucky or unlucky not sure. Looks a lot like 666.

-
Klaus
- Posts: 14205
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Mar 06, 2014 4:16 pm