Skip to main content

Posts

Showing posts with the label lua

Taking Random Values in Corona

Syntax for taking random numbers or values in corona has been given below. Download the code and try it... Syntax         math.random()          math.random( m )          math.random( m, n ) math.random() ---> a number between 0 and 1 math.random(m) ---> an integer between 1 and n (inclusive) math.random(m,n) ---> an integer between m and n (inclusive) math.random() ---> a number between 0 and 1 math.random(20) ---> an integer between 1 and 20 (inclusive) math.random(20, 40) ---> an integer between 20 and 40 (inclusive)

String Functions In Corona

Here is a list of string function which are very useful... string.byte() Returns the internal numerical codes of the characters in a string. string.char() Returns a string in which each character has the internal numerical code equal to its corresponding argument. string.find() Looks for the first match of a pattern in a string. If found, it returns the indices where the occurrence starts and ends; otherwise, returns nil. string.format() Returns a formatted string following the description given in its arguments. string.gmatch() Returns a pattern-finding iterator. string.gsub() Replaces all occurrences of a pattern in a string. string.len() Returns the length of a string (number of characters). string.lower() Changes uppercase characters in a string to lowercase. string.match() Extracts substrings by matching patterns in a string. string.rep() Replicates a string by returning a string that is the concatenation of n copies of a specified strin...

Read A Text File in Corona

Reading a text file in corona is very eazy.First get the file path and using the file path read the content in the file. Check the code below. display.setStatusBar( display.HiddenStatusBar ) -- read the file path local filePath = system.pathForFile( "myFile.txt", system.ResourceDirectory ) local file = io.open( filePath, "r" ) if file then -- read all contents of file into a string local contents = file:read( "*a" ) print( "The file path is" .. filePath ) print( contents ) io.close( file ) end Copy and download the code and try your self.

Tables In Corona

The table constructor is written using braces (curly brackets) as in { } t = {} -->create a table k = "x" t[k] = "tabvalue" --new table entry, -->with key="x" and value=2.4 print( t[k] ) --> 2.4 print( t["x"] ) --> 2.4 print( t.x ) --> 2.4 t[2] = "tabval2" --new table entry, -->with key=2 and value="tabval2" t[3]= 2.4 print( t[2] ) --> "tabval2" print( t[3] )

Function in Corona

Using functions are very eazy in Lua.We can provide arguments as input (within the parentheses), the function performs some tasks, and the results can be returned. Some ways to define functions are: local function f () --body end local f = function() --body end function f () --body end f = function () --body end

Types and Values In Corona

Lua is a dynamically typed language. This means that variables do not have types; only values do. There are no type definitions in the language. All values carry their own type. All values in Lua are first-class values. This means that all values can be stored in variables, passed as arguments to other functions, and returned as results. nil   — it usually represents the absence of a useful value. boolean   — represents two conditions 'false' or 'true' number   — represents real (double-precision floating-point) numbers. string   — represents arrays of characters. Lua is 8-bit clean: strings can contain any 8-bit character,   including embedded zeros. function   — click here to get more details table   — the sole data structuring mechanism in Lua.

Conventions In Corona

Names or Identifiers in Lua can be any string of letters, digits, and underscores, not beginning with a digit. The following keywords are reserved and cannot be used as names:           and     break        do          else     elseif      end        false           for      function      if             in         local       nil          not           or       repeat        return     then  ...

What is Corona?

Corona is cross platform game engine that supports Android and iOS. It’s developed by a company named Ansca, and you can use a free trial to try out Corona and develop your game. When you are ready to publish you are required to buy a license, prices range from $199 to $349. You program in Corona with a programming called Lua, which is a lightweight and easy to use scripting language. There is no IDE for Corona (such as Xcode), instead you often program with a normal text editor. Corona comes with a simulator you can use to test your game as you’re coding it. Corona has built-in APIs for the normal game programming aspects (sprites, sounds, etc.) as well as various APIs from the Apple including Game Center Leaderboards (new), In App Purchase, and TableViews (new). read more from here ....