it should be clear what JayantV explains.
but here are some more examples:
BASIC is an *imperative* language…
10 variable = 0
20 variable = variable + 1
30 print variable
40 goto 20
when the program is started, the “reading head” interprets the code line by line, just like plain HTML.
LUA, for instance, uses procedural (or structural) programming: the code is organized in procedures (aka subroutines, methods, functions), that are made up of chunks of imperative code which can be called from anywhere inside the code:
function addNumbers (a1,b1)
var c = a1 + b1
return c
end
function multiplyNumbers (a2,b2)
var c = a2 \* b2
return c
end
function addAndMultiplyAndSquareRoot (a3,b3)
var c = addNumbers (a3,b3)
var d = multiplyNumbers (a3,b3)
var e = math.sqrt (c + d)
return e
end
var myNumber = addAndMultiplyAndSquareRoot (5,3)
print (myNumber) -- output: 4,79583152331272
As you can see, the first two functions are used in the third to do the (lil’ silly) math. Usually you should create a function if you need a piece of code more than once. That is the case in most programs anyone writes today (and especially in games).
You need a moving ball?
Add n to the x- and y-coordinates on every frame inside a moveBall-function.
You want to check user input?
Write an onTouch-function that listens to tap events constantly.
Another program paradigm is OOP (object-oriented programming, e.g. used in obj-C and JAVA) where you create classes that take particular tasks of your program. Each class contains a set of it’s own functions.
In LUA you can use modules, which is not(!) OOP, but comparable…
so take a look at the posted link and start learning corona/LUA - FTW!
cheers
-finefin
[import]uid: 70635 topic_id: 16603 reply_id: 62122[/import]