How to make a function run?

From the wiki I learned there are six standard functions. Ok cool.

What happens when I make my own function? This is an example below

function startSound()
    sound(SOUND_POWERUP, 10)
end

i expected the function will play SOUND POWERUP 10 as soon as the code starts. If that works I can add some if else if clauses for if the user switches tabs or other things. Nope. Obviously my function is not running.

If there are multiple ways to make a function run I would appreciate you telling me that.

this may help your understanding https://coolcodea.wordpress.com/2013/03/10/starting-with-codea/

function setup()
    startSound() --will run your function
end

Thanks man. I was trying to say startSound = true but it wasn’t working lol. Is that the only way to do it?

I welcome you to the forum, but I suggest you do some reading before asking more questions, because we are a small community and we don’t have time to provide a guided tour of Codea.

I have ebooks on my website I linked you to, and there are other tutorials and documentation, and demo projects, too. Have a look at those, they should answer your initial questions.

Also google for tutorials on Lua, the underlying language behind Codea. They will explain how to use functions.

So, a quick tutorial on this:

To make a function run, you need a “trigger” for example:

function touched(touch)
If touch.state == BEGAN then
           startSound()
end

By doing this, codea reads this code, and if the state of touching has started, then codea will run startSound() which will refer to the function, startSound(), and run it.

You can do this with any function. Just remember those rules, and you will be on your way to app creating. :slight_smile: