How Can I Add A Sound To A Button

Hi Brent, Dr. Burton, Saer, And all my friends at Corona Forum

I am working now on my book finally!!!

See, I told you, I did not needed a lot of things to start working, it’s a simple book for children.

I have the storyboard working, I have so far 4 pages, the home and the main.

I can add pages, make simple animation, and I can add sound to the buttons.

So I’m really happy because now I can keep learning more, but start making my app now

Thank you for all your help, thanks Dr. Burton for your book.


One question, I think it’s very important…

Once I finish my book which it’s for the iPad ONLY, and I can see the final book in the Corona Simulator in my Mac…

what I see in my computer will be the same, and it will look and behave exactly the same as in a REAL iPAD?


And one more…

About money – I have to pay $99.00 per year to Apple for the developer program to upload my app to the app store

to see if they accept it, right?

And how much money do I have to pay to Corona for using the program?

Is there any more fees or money involved?


Thank you for everything.

Let’s see how long it takes me to write my book

Victor

Hi Victor,

It should look & behave the same, but I always check it on an actual device before I submit to Apple.  If you don’t have an iPad, remember, it is now a business expense since you are publishing apps!-)

On Apple: Yes, you have to pay Apple $99/yr to be a part of their developer program and to upload the app to the store.  

If you are using the starter program, you do not have to pay anything to Corona (though I am sure they would like to see you move up to Pro once your app is successful… we want them to stay in business!)

No additional fees beyond normal business fees (business license, paying taxes, etc).

I look forward to seeing your book!

Thanks Dr. Burton, I’m on page 13 now.

I’m working hard. I do have an iPad (I love it)

How can I see my book in the real iPad?

All I can see now it’s the simulator.

Thanks

Victor

Oh Dr. Burton and I’m still reading your book, it’s great.

But I can not figure it out the “RANDOM” Images problem.

I want to have a button ---- tap on it

and make a random image show — from 20 images.

Do you have a “SAMPLE CODE OF THAT”

just with that basic – function

I would really appreciated it very much

Thanks Dr. Burton

Victor

Hi Brent, Dr. Burton, Saer, Paytown, Somebody, Are you still there?

I guess I have been bothering too much…

But I have no other way to learn…


Please can someone help me out with a sample code to display random images?


And also how to remove an image from the view, after I use it? – in storyboard


I have an image in enterScene in a group, and I insert that image in the group

I apply some transition.to to move the image,

but when I comeback to the same scene again,

the image is there, in the last place of the transition.to and the animation stars again, so now I have a duplicate image.

Today is Monday , may 6 at 2:11 pm

Victor

Today is may 7 at 2:59 pm

I guess I’m on my own…

Victor, I might suggest that you use a new forum post when your topic changes.  Most people see “How to add a sound to a button” show up and see that it’s a long thread and they might not want to read such a long thread.   Now that doesn’t mean go create dozens of threads.  You do need to try to figure out some of this on your own.   Read, Google, Watch YouTube tutorials.  And ask direct questions showing people code when your stuck.

As for this particular question, you want to learn about tables/arrays and how you can build a table of image file names that you will pick randomly from and how to use tables.  You need to learn how math.random works.  Once you have the random file name, you need to know how to use display.newImage() or display.newImageRect() to get the image on the screen at a particular location.

As for your problem, if you want to remove it by itself, look up object:removeSelf() or display.remove().  If you want your whole storyboard scene gone, look up storyboard.purgeScene().

Hi BRENT!

I’m back… (I know, sorry)

I’m reading Dr. Burton’s Book, it’s really good, BUT I DON’t see anywhere HOW TO CHANGE THE PAGE.

I have a book, one page only (main.lua) I can do a lot of nice things in just ONE PAGE or one view or one file, I don’t know the correct name.

now I want to go to another page in my book, or another scene, or another view.

Would you please tell me how to do that?

Thank you Brent

Victor

Testing: I just want to see If I can add a video here

https://www.youtube.com/watch?v=9u21eSR4O1E

IT WORKS!!!

Now I can explaing things better, GOOD!

Hi Rob…

Thanks for been so patient with me, I’m learning, and I’m sorry if I don’t do thinks the way they should be done.

I guess I have to follow the same RULES as everyone else, (Even if they don’t make sense to me now)…maybe later.


– You do need to try to figure out some of this on your own.   Read, Google, Watch YouTube tutorials.


I read, and I watch so many videos, and nothing…

I read this:

What is a scene purge?

Storyboard scene objects can have a scene.view property, which is a display group that holds all display objects for the scene. When a scene is purged, the scene.view
display group is completely removed (freeing all associated texture
memory), but the module still remains in memory. If you want the module
to be removed as well, use storyboard.removeScene() or storyboard.removeAll() instead.

and it has this sample…

local storyboard = require “storyboard”

– Purge all scenes (except for the one that is currently active)
storyboard.purgeAll()

------------------------------------------------ AND THAT’S IT…

I put that code here…

– --==***************************[EXIT SCENE]**********************************+±- –

function scene:exitScene( event )
    local group = self.view
    
    storyboard.purgeAll()
end

-------------------------------------- IT DOESN’T WORK

I try it at the end of the code…

– --==*************************[EVENT LISTENER]*********************************+±- –

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

storyboard.purgeAll()

return scene

-------------------------------------- IT DOESN’T WORK

At the beginning of the code

– --==***************************************************************************+±- –
– Music Theory Game
– By Victor M. Barba
– Copyright 2013 – All Rights Reserved

– Version 1.0
– --==***************************************************************************+±- –

local storyboard = require( “storyboard” )
local widget = require “widget”
local scene = storyboard.newScene()
local wrongSound = audio.loadSound( “wrongSound.mp3”)

storyboard.purgeAll()

-------------------------------------- IT DOESN’T WORK

THIS IS MY COMPLETE CODE


– --==***************************************************************************+±- –
– Music Theory Game
– By Victor M. Barba
– Copyright 2013 – All Rights Reserved

– Version 1.0
– --==***************************************************************************+±- –

local storyboard = require( “storyboard” )
local widget = require “widget”
local scene = storyboard.newScene()
local wrongSound = audio.loadSound( “wrongSound.mp3”)

– --==******************[FUNCTIONS TO GO TO ANOTHER SCENE]**********************+±- –

local function buttonLearnLevel1()
        storyboard.gotoScene( “level1Q1”, “crossFade”, 1000 )    
    return true
end

– --==**************************[CREATE SCENE]**********************************+±- –

function scene:createScene( event )
    local group = self.view
    
    local background = display.newImage( “backgroundWrong1.png” )
    
    buttonLearnLevel1 = widget.newButton{
        defaultFile=“buttonWrong1release.png”,
        overFile=“buttonWrong1over.png”,
        onRelease = buttonLearnLevel1
    }
    buttonLearnLevel1.x = 890
    buttonLearnLevel1.y = 650
    
---------------------------------------------------------------------insert into group----
    
    group:insert ( background )
    group:insert ( buttonLearnLevel1 )
    
end

– --==***************************[ENTER SCENE]**********************************+±- –

function scene:enterScene( event )
    local group = self.view
    
    local littleBees = display.newImage (“littleBees.png”)
    littleBees.x = 28
    littleBees.y = 30
    transition.to(littleBees, {x=487, y=65, time=3000})
    
    group:insert ( littleBees )
    
    
    
end

– --==***************************[EXIT SCENE]**********************************+±- –

function scene:exitScene( event )
    local group = self.view
    
end

– --==**************************[DESTROY SCENE]*********************************+±- –

function scene:destroyScene( event )
    local group = self.view    

    
    if buttonLearnLevel1 then
        buttonLearnLevel1:removeSelf()
        buttonLearnLevel1 = nil
    end
    
    if littleBees then
        littleBees:removeSelf()
        littleBees = nil
    end
        
    
end

– --==*************************[EVENT LISTENER]*********************************+±- –

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene


isn’t it much more easier if you already know, PLEASE, let me know where I should put that line of code,

instead of my trying every single possible way, myself

it will take me 3 or 4 weeks or more, maybe six months,

is that why it takes that long to learn to make apps?

The actual programming is not difficult…

finding the answers IS THE PROBLEM.

Believe me Rob, I have read the CORONA DOCS, when I need something, but IS NOT CLEAR AT ALL

is too technical, and is doesn’t have SIMPLE REAL SAMPLE CODES THAT YOU CAN APPLY.

I DON’T WANT TO BOTHER YOU or anyone else, I’m sorry if I’m been asking too many questions

my problem is that I’m 52 years old, I’m not 20, and I don’t have a lot of time left, so I want to learn faster

I know I can, with your help.

I hope this is not too long but I had to let you know how I feel.

Thank you

Victor

P.S. Please tell me how to go to another topic. This will be the last one in this one.

Hi victor,

As i said, If you could sit and read through that book you just bought you would have your answer for random images. If you have the same book that i have "Mobile App Development with Corona, turn to page 129,  (Game Design) and read through the next 3 pages. The function you need is math.random() first used on page 134.

So when you have to learn something new like this, head over to the CORONA SDK API page and search for code or fuction you need.

for example you need a RANDOM number generator. therefore, go to the API SDK page ->

http://docs.coronalabs.com/api/index.html

Next top right corner type Random, and you’ll see the first link will be exactly what you need!

Now heres where the importance of READING through the entire book and doing sum examples from there is a MUST for you, trying to CODE without reading the whole book will cause you to continually get stuck on simple things. You have time, so dont worry, reading through the book can be done in a month. 

So please try and set aside your project JUST until you can get through the book.

As I was saying this is an example of roadblocks you will hit if you DONT read through the book to understand concepts

from the API, it would tell you clearly how to use math.random() ->

http://docs.coronalabs.com/api/library/math/random.html (examples at bottom)

But how wud you do it with images?

If you read from page 130 to about 135 You would see a very similar situation.

You need an Array, or a Table, which is basically a 2d structure or memory store.

So first you would define an array,

and add your images to that array.

Never forget the power of google!!! Just typing “Corona sdk add images to an array” will get you some good links

Some links ->

http://www.coronalabs.com/blog/2011/06/21/understanding-lua-tables-in-corona-sdk/

Here is an answer you can adapt :-

http://thatssopanda.com/corona-sdk-tutorials/creating-several-images-with-corona-sdk/

i found this just by googling. But thing is, Like you I would not have known to search for “adding images to an Array or table” if i didnt read.

So trust me, set aside yr project. and go through the book, if you read it all day, you could be done in 10 - 15 days even. Without that you are learning the WRONG way, which is why you get stuck at every point.

Im not saying you are not trying, but In life, you have to WORK SMART. so If you had given the book a good read, and coded the examples in it, you would have seen and understood how you could do yr images.

FOR EXAMPLE :-

You read page 120 - 135.

you get to the part where doctor burton talks about adding images to an array "Each asteroid is loaded into our array of asteroids (stored in asteroidsTable).

After they are loaded into the array, I used a random number generator"

and you would be like, hey, what is an array ->

then google “programming concepts - array”

and the second link would help you understand.

So even if you ARE trying to hack slash code the way you are, pasting it here and trying it there, The PROBLEM is not that you’re not trying,

You’re not UNDERSTANDING, so you have no idea to debug or even see why its not working. 

Again, -> Put your project aside, and READ the book, and CODE the examples as you go along.

Another very important thing ->

WHAT are you using to CODE? Notepad X-code? Corona project manager?

I use LUA Glider -> helps to tell you where errors are and is a nice IDE (integrated development env), basically a tool to help you code ->

try it - > http://www.mydevelopersgames.com/CIDER/

Cheers

You can’t purge the scene you are currently in. 

Hi Victor,

The official supported scene management for Corona is Storyboard. I’m not sure if Dr. Burton’s book has a chapter on that, but you’ll need to learn how to use it eventually.

http://docs.coronalabs.com/api/library/storyboard/index.html

It’s not exactly “difficult” to learn, but I suggest that you continue with other topics before you attempt this. A solid foundation in Lua and Corona should be established before you attempt scene management.

Brent

Hi Jacsparrow.

Thanks for helping me. I will read the book for the third time. But maybe I have a different book.

In page 129 03 134 it’s only “Phun with physics” NO ARRAY OR TABLES, sorry.

As for the CORONA DOCS, I read that several times,

-------------------------------------------------------------------------------------I WILL READ IT AGAIN WITH YOU------

table.insert( t, value ) table.insert( t, pos, value )

t (required)

Array.
A table to which the new value will be added. When a table has an
element inserted both the size of the array and the element indices are
updated.

pos (optional)

Number. The index of the table at which the new element will be inserted. The default value is the length of the table + 1 so that table.insert(t,x) inserts x at the end of table t. Note that it is faster to use the length operator: t[#t + 1] = x.

value (required)

Any. The new value to assign to be inserted into the table.

------------------------------------------------------------------------------------I READ THAT---------------

Still is not telling me how to use it. I don’t even know what’s t[#t + 1] = x


You guys win, programming IS DIFFICULT, I give up.

Thank you for everything.

Victor

P.S.

Oh ROB –

you told me this – You can’t purge the scene you are currently in. – THAT I KNOW I CAN’T –

That’s why I ask you if you can tell me HOW I CAN.

But I this point I think IT’S TOO MUCH.

I purge my scenes before I go to them.

Hi Brent!

I think I got it!!!

I can change to another view in storyboard,

I can change with a button that I created with thw widget

I can add more views or levels, and I can go to any level I want.

Saer sent me a zip file with that and a few hours of my time I GOT IT!

Thanks for all your help.

NO Dr. Burton books does not talk about storyboard…


Now I can start making my book!

one question –

How can I make the background image .png fill the entire view in the iPad simulator?

My file is .png 1024 X 768 Landscape, but when I display.newImage the file fills only 3/4 of the screen why?

Victor

Hi Victor,

In your “config.lua” file, do you have the “width” setting as the lesser value, and the “height” as the higher value? For example:

[lua]

content = 

{

    fps = 30,

    width = 768,

    height = 1024,

    scale = “letterbox”,

    xAlign = “center”,

    yAlign = “center”,

}

[/lua]

Brent

Victor, 

That eBook came out before there was such a thing as Storyboard.  I am covering storyboard in the new textbook and will address storyboard in the next update of the book you have.

Glad you got it to work!

Dr. Burton

Hi Brent, Dr. Burton, Saer, And all my friends at Corona Forum

I am working now on my book finally!!!

See, I told you, I did not needed a lot of things to start working, it’s a simple book for children.

I have the storyboard working, I have so far 4 pages, the home and the main.

I can add pages, make simple animation, and I can add sound to the buttons.

So I’m really happy because now I can keep learning more, but start making my app now

Thank you for all your help, thanks Dr. Burton for your book.


One question, I think it’s very important…

Once I finish my book which it’s for the iPad ONLY, and I can see the final book in the Corona Simulator in my Mac…

what I see in my computer will be the same, and it will look and behave exactly the same as in a REAL iPAD?


And one more…

About money – I have to pay $99.00 per year to Apple for the developer program to upload my app to the app store

to see if they accept it, right?

And how much money do I have to pay to Corona for using the program?

Is there any more fees or money involved?


Thank you for everything.

Let’s see how long it takes me to write my book

Victor