Page 1 of 1

Long Delay & None Responsive Buttons

Posted: Tue Feb 18, 2014 2:54 pm
by istech
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

Re: Long Delay & None Responsive Buttons

Posted: Tue Feb 18, 2014 10:18 pm
by jacque
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.

Re: Long Delay & None Responsive Buttons

Posted: Wed Feb 19, 2014 5:28 pm
by istech
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)

Re: Long Delay & None Responsive Buttons

Posted: Wed Feb 19, 2014 8:26 pm
by jacque
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

Re: Long Delay & None Responsive Buttons

Posted: Thu Feb 20, 2014 12:20 pm
by istech
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.

Re: Long Delay & None Responsive Buttons

Posted: Thu Feb 20, 2014 2:08 pm
by Klaus
Hi istech,

will you reveal to us what -> specialFolderPath("pathBase") is?
Thank you! 8)


Best

Klaus

Re: Long Delay & None Responsive Buttons

Posted: Thu Feb 20, 2014 11:40 pm
by istech
Oh, do you mean the stack-tasic function the LC gurus came up with that I use in every stack from now on. :wink:

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. :D

Re: Long Delay & None Responsive Buttons

Posted: Fri Feb 21, 2014 8:10 pm
by jacque
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"

Re: Long Delay & None Responsive Buttons

Posted: Fri Feb 28, 2014 12:00 pm
by istech
Thanks Jacque

Your right it would work in ide but not complied/standalone until I updated the code thanks.

Re: Long Delay & None Responsive Buttons

Posted: Fri Feb 28, 2014 2:16 pm
by Klaus
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. :wink:
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 8)

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 :D

Re: Long Delay & None Responsive Buttons

Posted: Thu Mar 06, 2014 3:30 pm
by istech
Yes very interesting Klaus,

However I never got any errors and no extra files. Maybe I got lucky :wink:

Re: Long Delay & None Responsive Buttons

Posted: Thu Mar 06, 2014 3:35 pm
by Klaus
Too funky! :D

Oh, I just noticed my number of postings :shock:
OK, here's to you and me:
dunkles-bier-im-glas-auf-weisem-hintergrund.jpg
:D

Re: Long Delay & None Responsive Buttons

Posted: Thu Mar 06, 2014 4:03 pm
by istech
Cheers 8) you will be at 6666 in no time. Is that lucky or unlucky not sure. Looks a lot like 666. :twisted: 8)

Re: Long Delay & None Responsive Buttons

Posted: Thu Mar 06, 2014 4:16 pm
by Klaus
istech wrote:Cheers 8) you will be at 6666 in no time. Is that lucky or unlucky not sure. Looks a lot like 666. :twisted: 8)
"apage ananas" (ananas = german for pineapple)
:D :D :D