Showing posts with label data. Show all posts
Showing posts with label data. Show all posts

Saturday, 26 October 2013

How to split complex strings in corona SDK

This session will teach you about splitting complex string of data separated with some characters. Lets assume that you have a string as House;home,40|Bed,20|Mirror,10. Now we will show you how to split each word and assigning each to a table.



  local myString = "House;home,40|Bed,20|Mirror,10"
  local myTable = {}
  for word in string.gmatch(myString, '([^,|]+)') do
     -- 'myTable' contains the data you need
    myTable[#myTable+1]=word print( myTable[#myTable] )
   end


Hence you will get the items as each table elements, as:
  
  myTable[1] = House
  myTable[2] = home
  myTable[3] = 40
  myTable[4] = Bed
  myTable[5] = 20
  myTable[6] = Mirror
  myTable[7] = 10

Wednesday, 24 July 2013

Auto-change the physics of an object (created using Physics Editor) after a change of it's size in corona SDK

If you are using physics editor for making physics objects in your corona game, then at some point you may doubted about how to scale the physics area according to the sprite scale values... But it is very simple.

For doing such alternation, there is scaleFactor provided. You can assign physics to the object with this scale factor, as below:

    local scaleFactor = 1.0
    local physicsData = (require "shapedefs").physicsData(scaleFactor)
    local shape = display.newImage("objectname.png")
    physics.addBody( shape, physicsData:get("objectname") )


And when you change the scaleFactor, the size of physics area will automatically change.

Saturday, 8 June 2013

How to print data : PHP

You can use 'echo' to print string, variables, etc. in php. 

Syntax:

        echo "print it...";                       // Output------------->  print it...
        echo '<br/>';                           // prints a new line/enter

        $var_1 = 10;
        $var_2 = 3.14;
        $var_3 = "myString";
        echo $var_1;                           //  Output (number)------->  10
        echo $var_3;                           //  Output (string)------->  myString
        echo "$var_1 + $var_2";         //  Output (sum number)-------> 13.14
       
       echo '$var_1 + $var_2';          //  Output (string)-------> $var_1 + $var_2
       
       echo "$var_1 + $var_2 = ".($var_1 + $var_2);  
       // Output ---------> $var_1 + $var_2 = 13.14


      Note: dot(.) character is used to concant/join strings in php.